通常客户会要求不使用web页面打印的方式,而是使用套打方式实现需求功能。此时我们可以采用jatoolsPrinter去实现该打印功能,简单介绍使用说明:
1、jatoolsP.cab文件是必须的,可以放在jsp页面的同级目录下。
2、套打对应的图片文件也可以放在同级目录。
3、jsp页面实现如下:
<html>
<head>
<!-- 插入打印控件 -->
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255" codebase="jatoolsP.cab#version=1,2,0,5"></OBJECT>
<style><!--
*{
-moz-box-sizing: border-box;
}
.hide_for_jatools_print{}
.jc{position:absolute;overflow:hidden}
.jnc{position:absolute}
.pb{background:white;float: left;overflow:hidden;margin:10;width:830;height:480;background-color:white;border-left:1px solid black;border-top:1px solid black; border-right:4px solid black;border-bottom:4px solid black;}
.c7,.c6,.c5{margin-left:2px;margin-bottom:-2px;text-align: center;font-family: 宋体;font-size: 36px;font-weight: bold;color: #FF0000}
.c4,.c3,.c2,.c1,.c0{margin-left:2px;margin-bottom:-2px;font-family: 宋体;font-size: 12px;}
--></style><script>
document.print_settings=new Object();
document.pageCount=2;
document.print_settings.orientation=1;
document.print_settings_id='null';
document.documents=document;
document.shapesUsed=false;
document.copyrights='杰创软件拥有版权 www.jatools.com';
</script><title>销售计量专用发票</title>
<script>
function doPrint(how)
{
if(typeof(jatoolsPrinter.page_div_prefix)=='undefined'){
alert("请按页顶上的黄色提示下载ActiveX控件.如果没有提示请按以下步骤设置ie.\n 工具-> internet 选项->安全->自定义级别,设置 ‘下载未签名的 ActiveX ’为'启用'状态")
return ;
}
//打印文档对象
var myreport ={
documents: document, // 打印页面(div)们在本文档中
copyrights : '杰创软件拥有版权 www.jatools.com' // 版权声明必须
};

// 调用打印方法
if(how == '打印预览')
jatoolsPrinter.printPreview(myreport ); // 打印预览
else if(how == '打印')
jatoolsPrinter.print(myreport ,true); // 打印前弹出打印设置对话框
else if(how == '直接打印')
jatoolsPrinter.print(myreport ,false); // 不弹出对话框打印
}
</script>
</head>
<body bgcolor="#AAAAAA">
<%
String id = request.getParameter("ID");
List list = new ArrayList();
list = PreparePrintSLDJData.getPrintSLDJListById(id);
System.out.println("==========获得打印单据id============" + id);
String tzrq = "";
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
tzrq = sdf.format(date);

int grTotalMondy = 0;

PrintSLDJListForm plf = null;
if(list.size() > 0 )
{
plf = (PrintSLDJListForm)list.get(0);
}
%>

<%
if(list != null && list.size() > 0)
{
int totalPage = list.size() / 3 + 1;
int startNum = 0;
int endNum = 6;
for(int i=1 ; i <= totalPage ; i++)
{
//公共部分的表头信息
%>
<div id="_page_<%= i%>" class="pb" ><div id="page<%= i%>">
<div class="jnc" STYLE="left:0; top:0;clip:rect(0,820,450,0)">
<img class='hide_for_jatools_print' src="shouliao.jpg" width="800" height="450"></div>

<div class="jc" STYLE="left:200; top:85; width:90;height:20"><p class="c0" style="margin-top:4px;"><%=plf.getDepartment()%> </p>
</div>

<%
if(i < totalPage)
{
startNum = (i - 1) * 3;
endNum = (i - 1) * 3 + 3;
}else if(i == totalPage){
startNum = (i - 1) * 3;
endNum = list.size();
}

int top=0;
String topn = "";
int k = 0;
for(int j = startNum ; j < endNum ; j++)
{
plf = (PrintSLDJListForm)list.get(j);
top = 170 + k * 35;

topn = top + "";
//列表显示的数据信息,已经实现了分页打印

%>
<div class="jc" STYLE="left:50; top:<%=topn%>; width:90;height:20"><p class="c0" style="margin-top:4px;"><%=plf.getGoodType()%> </p>
</div>
<div class="jc" STYLE="left:240; top:<%=topn%>; width:90;height:20"><p class="c0" style="margin-top:4px;"><%=plf.getUnit()%> </p>
</div>
<div class="jc" STYLE="left:320; top:<%=topn%>; width:90;height:20"><p class="c0" style="margin-top:4px;"><%=plf.getQuantity()%> </p>
</div>
<div class="jc" STYLE="left:400; top:<%=topn%>; width:90;height:20"><p class="c0" style="margin-top:4px;"><%=plf.getGrPrice()%> </p>
</div>
<%
k++;
if(k == 3 * i) break;
}
%>

</div>

</div>
<%
}
}
%>

<table border="0" cellpadding="0" cellspacing="0" width="100%" id="print" height="206">
<tr>
<td width="33%" height="206" valign="top">
<input type="button" value="打印" onClick="doPrint('打印')">
<input type="button" value="直接打印" onClick="doPrint('直接打印')">
<input type="button" value="打印预览..." onClick="doPrint('打印预览')">
</td> </tr>
</table>
</body>


套打主要工作(1、取数据,2、针对图片调整显示位置)页面中left 和 top参数对应数据显示的位置。
可参照http://joerong666.javaeye.com/blog/182809 使用手册
评论
wmj2003 2008-07-21
你有这个版本吗?我在网上找了很久都没有找到。烦请给我传一份wmj2003@163.com十分感谢。
版本号:jatoolsP.cab#version=1,2,0,7
pancras 2008-06-16
haowen
发表评论

您还没有登录,请登录后发表评论

pacer123
搜索本博客
最近加入圈子
最新评论