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="打 印" onclick="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=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 onclick=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="打 印" onclick="print();">
<input type=button name=button_show value="打印预览" onclick="preview();">
<input type=button name=button_setup value="打印设置" onclick="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>
分享到:
相关推荐
电信设备-基于局域网的移动终端网页打印方法.zip
vue实现页面打印自动分页的两种方法 本文实例为大家分享了vue实现页面打印自动分页的具体代码,供大家参考,具体内容如下 一、通过ref方式获取元素进行打印 1.封装一个js文件 // 打印类属性、方法定义 /* ...
将网页中数据表以pdf方式打印,网上发布的相关解决方法都属于互相copy,且不完善,有很多漏洞。当初我在做的时候为此非常头疼,最后查看了很多资料,将次功能最终实现,为方便大众,将个人的例子上传,以供需要的...
利用javascript在网页上实现打印的方法,可以设置分页等页面设置。
主要介绍了js调用iframe实现打印页面内容的方法,需要的朋友可以参考下
里面是 jsp 打印的各种方法实现 简单实用, 供大家下载参考,我从中也学到很多东西
批量打印 HTML:打印页面预览,跳转到打印那边使其 分页(使每个报告单占据一页)
水晶报表ActiveX 打印(web打印) 解决方法 解决控件无法安装, 安装控件也没卡死 部署到到服务器打印一闪而过。
常用的网页打印的方法,非常不错,可以设置打印区域
在IE浏览器打印中由于版本问题,可使用打印控件打印,如果打印控件打印不兼容,可以使用IE自带的打印功能
打印的JS方法,可把页面上的内容直接打印出来
前端LodopFuncs.js打印,js打印,web打印,jq打印,html打印,不需要经过预览页面 直接调起默认打印机进行局部打印。该打印js可局部打印也可全局打印而且该驱动试用版也能正常使用打印功能。局部打印功能和jQuery....
网页WB_ExecWB控件打印方法,及各个参数的详细介绍.
使用jatools2.0 实现网页打印功能。这是我写的一个小实例,比较简单。
JS怎么实现页面打印呢?JavaScript 实现打印,打印预览,打印设置;JS打印和报表输出;原生js打印插件Print.js;js控制分页打印、打印分页示例;js 打印插件;js使用window.print()实现打印功能;代码仅5kb; 自主研发...
资源名称:用javascript实现页面打印的三种方法资源截图: 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
打印方法小议,页面设置对话框、打印预览对话框、打印对话框等功能,C#源代码 //字符串流对 象,一行一行读取文本 private StringReader MyReader; private void button1_Click(object sender, EventArgs e) { ...
这是我从网上下载的一个收费的科技文摘,是关于WEB打印的。讲解的还比较全面,基本上能解决在WEB页面中打印的难题。 共享了……
java POI 如何操作EXECL表的打印页面设置,应用较少,但用好了可收到“一键预览打印的格式效果”,各打印页面要素设置方法汇集于这里,亲测成功,方法齐全,共大家参考。
web打印的三种方法。非常方便。很好很强大,谁用谁知道。