jsp页面打印方法

JSP页面打印方法

方法一:
function PrintTable(Id){
                 var mStr;
                 mStr = window.document.body.innerHTML ;
                 var mWindow = window;                
                 window.document.body.innerHTML =Id.innerHTML;
                 mWindow.print();
                 window.document.body.innerHTML = mStr;
         }

在页面中要打印
<div id="dy">
.......
</div>
<input type="button" value="打    印" οnclick="return PrintTable(dy)">

方法二:
/*-----------print.js
Copyright (c) 2002,*************
All rights reserved.
Filename :print.js
Abstract :常用打印函数
Version :1.0
Author    :Liu Guoyuan
Finished Date :2003-03-19
Last Modified :2003-03-20
-------------------------------------------------------------------------------------
*/

with (document)
{//输出样式表表及IE打印控件
         write ("<style type=/"text/css/" media=/"print/">");
         write ("   .noPrint{visibility:hidden}");
         write ("</style>");
         write ("<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WB width=0></object>");
}
function doPrintSetup()
{//打印设置
         WB.ExecWB(8,1);
}
function doPrintPreview()
{//打印预览
         WB.ExecWB(7,1);
}
function doPrint()
{
         window.print();
}
function showPrintBar()
{
         with (document)
         {
                 write ("<div align=/"center/" class=/"noprint/">");
                 write ("   <input type=/"button/" name=/"doBack/" value=/" <<返回   /" onClick=/"history.go(-1)/">");
                 write ("   <input type=/"button/" name=/"doPrintPreview/" onClick=/"WB.ExecWB(8,1)/" value=/"打印设置/">");
                 write ("   <input type=/"button/" name=/"doPrint/" value=/"   打印>> /" onClick=/"doPrint()/">");
                 write ("</div>")
         }
}

----------------print.js end------------

页面中使用时:
<script language="JavaScript" type="text/JavaScript" src="print.js"></script>
然后再需要输出打印按钮时:
<script>showPrintBar()</script>

方法三:
打印前把按钮隐藏
<tr><td><input type="button" value="打 印" name="butt" onClick="javascript:hide()"></td></tr>

<script language="javascript">
                 function hide()
                 {
                    document.all.item("butt").style.display="none";
                   
                    window.print();                                
                   }
</script>

方法四:
<style>
@media print{
.noprint{display:none}
}
</style>
给不打印的区加这个CSS就可以了,在页面上能看见但打印的时候看不到!

方法五:
利用脚本控制打印,可以采用如下方法:
1、execCommand()方法
Print 打开打印对话框以便用户可以打印当前页
即document.execCommand('Print');

2、window.print()

3、   <OBJECT   id=WebBrowser   classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2   height=0   width=0>
   </OBJECT>
   <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)>

方法六:
<%@ page contentType="text/html; charset=GBK"%>
<%
String url="#"
%>

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

<body>

<jsp:include page="<%=url%>" />
<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>

</body>
<object id="factory" style="display:none" viewastext
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="/etsc/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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值