项目中需要使用web页面的打印功能,所以选用了IEWebBrowser组件,下面总结一下使用到的内容:
直接在JSP页面中添加如下代码,就可以使用了:
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>
但是当我进行打印预览时发现并非所有的网页内容都是需要打印的,所以采用以下方式将不需要打印的内容排除在外:
<style type="text/css" media=print>
.noprint{display : none }
.PageNext{page-break-after: always;}
</style>
<p class="noprint">
不需要打印的内容
</p>
使用这种方式就可以将不需要打印的内容屏蔽掉。
那上面还有一个PageNext样式有什么作用,答案是分页时使用,我们可以在需要打印分页的地方添加如下代码:
<div class="PageNext"></div>
遇到上述标记,就会进行分页打印。
另外,在我的打印功能中还遇到了一个问题,那就是分页表头的问题,我发现只有第一页有表头,而第二页开始就没有表头了,采用以下方法可解决此问题,使打印的每一页都具有相同的表头:
<thead style="display:table-header-group;font-weight:bold">
<tr><th colspan="13"><b style="font-size:15px;">工人入场三级安全教育考核汇总登记表</b></th></tr>
<tr>
<th colspan="5"><b style="font-size:13px;">单位:<bean:write name="workerForm" property="unit.unitName" /></b></th>
<th colspan="4"><b style="font-size:13px;">登记日期:<bean:write name="workerForm" property="unit.registerDate" format="yyyy-MM-dd"/></b></th>
<th colspan="3"><b style="font-size:13px;">编号:<bean:write name="workerForm" property="unit.unitId" /></b></th>
</tr>
<tr>
<th><b style="font-size:13px;">序号</b></th>
<th><b style="font-size:13px;">姓名</b></th>
<th><b style="font-size:13px;">性别</b></th>
<th><b style="font-size:13px;">年龄</b></th>
<th><b style="font-size:13px;">工种</b></th>
<th><b style="font-size:13px;">籍贯</b></th>
<th><b style="font-size:13px;">身份证号码</b></th>
<th><b style="font-size:13px;">教育考核时间</b></th>
<th><b style="font-size:13px;">考核成绩</b></th>
<th><b style="font-size:13px;">教育卡号</b></th>
<th><b style="font-size:13px;">照片</b></th>
<th><b style="font-size:13px;">操作</b></th>
</tr>
</thead>
只要应用了蓝色代码部分的样式,则表头就会出现在每一页中。
分享到:
相关推荐
IEWebBrowser组件用法详细使用方法描述文档。。
iewebbrowser组件的execwb方法IEWebBrowser组件的execWB方法整理。 1. <object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object> 2. 调用方法。 WebBrowser....
利用IE内置打印控件IEWebBrowser进行打印.
博客演示代码,演示了IE WebBrowser控件的基本使用,包括静态创建、动态创建和事件响应。
使用ie内部的webbrowser组件对单独页面进行打印。 1.打印预览。 2.页面样式最好使用%。
WebBrowser组件和MSHTML 在Delphi中的使用.doc
验证码 填表 IE webbrowser 验证码 填表 IE webbrowser
使用WebBrowser控件打印页面demo,通过修改demo中的几行代码就可以使用
在使用WebBrowser控件,先要 初始化和结束程序后要终止化(Initialization & Finalization) 自定义浏览器上下文菜单 自定义浏览器 C#中调用WebBrowser查看源文件的功能 ----------------------------------- ...
具体见https://blog.csdn.net/whx19881209/article/details/118384572
winform 使用webBrowser控件 打印,利用拼接字符串格式填充html标记 并添加javascript 函数 在后台程序中调用
MFC ie webbrowser对网页控件的选中、设值、延时以及iframe框架下控件的寻找
VB基于WebBrowser组件打开Word文件,显示Word文档的内容,本程序以WebBrowser为窗口,装载Word文档,并显示其中的内容,非常方便的调用word文件的内容,有兴趣的不妨一试。
WebBrowser控件使用详解,WebBrowser控件使用详解
BS架构下的打印大家是怎么解决的呢,我最近作了一个项目正好负责这一块,不仅要求打印页面的特定部分,还要求有后台的批量打印,在网上查了一些资料,最后终于解决了。抱着“取之于众服务于众”的思想,我总结了一下...
C# WebBrowser 适应你想要的IE版本核心 方便你在内嵌式C/S 更好的体验B/S
对一些使用了WebBrowser的控件的软件,由于默认IE版本设置不兼容网站的内容的,可以使用此工具来修改软件使用的IE版本,能够浏览正确的网页
具体见https://blog.csdn.net/whx19881209/article/details/118384572