简单打印功能实现

 

先构造printRep.jsp

<%@ page contentType="text/html; charset=gb2312" %>
<%

String printUrl;
if (request.getParameter("printUrl")!=null)
printUrl=request.getParameter("printUrl");
else
printUrl="";
%>

<style media="print">
     .noPrint { display: none }
   </style>
   <style media="screen">
      .print { display: none }
</style>
<html>
<title></title>

<body>


<table width="100%" class="noPrint" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" align="center">
<input type=button name=button_show value="打     印" οnclick="print();">
<input type=button name=button_show value="打印预览" οnclick="preview();">
<input type=button name=button_setup value="打印设置" οnclick="pageSetup();">
</td>
</tr>
</table>
<jsp:include page="<%=printUrl%>" />
</body>
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/ActiveX/ScriptX.zip#Version=6,1,430,5">
</object>
<script language="javascript" >
function pageSetup()
{
   factory.printing.PageSetup();
}
function preview()
{
   setPageInfo();
   factory.printing.Preview();
}
function print()
{
   setPageInfo();
   factory.printing.Print(true);
}

function setPageInfo(){
   //factory.printing.header = "&b&b第&p页/共&P页"
   //factory.printing.footer = "&b&b时间:&D&T"
   factory.printing.footer = ""
   factory.printing.leftMargin = 10
   factory.printing.topMargin = 20
   factory.printing.rightMargin = 10
   factory.printing.bottomMargin = 20
}
</script>
</html>

 

<%@ page contentType="text/html; charset=GBK"%>
<%
String url="../printRep.jsp?printUrl=/XXXXXX.jsp?id="+123;
%>
<jsp:include page="<%=url%>" />

 

 

<style media="print" type="text/css">
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"
     width="0">
</object>
<center class="Noprint" >
<input type="button" value="打印" οnclick="document.all.WebBrowser.ExecWB(6,1)" />
<input type="button" value="直接打印" οnclick="document.all.WebBrowser.ExecWB(6,6)" />
<input type="button" value="页面设置" οnclick="document.all.WebBrowser.ExecWB(8,1)" />
<input type="button" value="打印预览" οnclick="document.all.WebBrowser.ExecWB(7,1)" />
</center>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值