一个跨平台的web打印插件,自动分页 hiprint 官网 www.hinnn.com
hiprint 是一个web 打印的js组件,无需安装软件。支持移动端,PC端浏览器,angular,vue,react, 等 分页预览,打印,操作简单,运行快速。预览界面为css+html 。支持数据分组,批量预览。生产pdf,图片更方便
可以在window,ios,linux 系统浏览器快速运行。
可视化配置模板,自动分页打印。
一个跨平台的web打印插件,自动分页 hiprint 官网 www.hinnn.com
hiprint 是一个web 打印的js组件,无需安装软件。支持移动端,PC端浏览器,angular,vue,react, 等 分页预览,打印,操作简单,运行快速。预览界面为css+html 。支持数据分组,批量预览。生产pdf,图片更方便
可以在window,ios,linux 系统浏览器快速运行。
可视化配置模板,自动分页打印。
转载于:https://www.cnblogs.com/thank/p/11022782.html
添加css: page-break-before:always 实现分页
window.print()//实现打印
转载于:https://www.cnblogs.com/chenlw/p/9198578.html
最近开发单位内部系统中的档案管理时,档案管理员提出需求,希望在打印档案盒中卷内目录,分页打印,因为目前的打印针对超过一页的档案记录,在第二页中无法显
示表头,还会出现表格断开不连续如图:
档案管理员想打印时,系统自动分页并且每页都有表头 如图
解决方案就是确定每页记录数,这里设置每页15个记录
经改进:1.增加了分页显示,档案管理员可以根据选项卡,查看或打印该页。
2.在右上角增加【打印全部页】复选框,勾选,则打印所有页,不选只打印当前页。
具体实现:
利用了css page-break-before:always;
注意:不能使用 page-break-after:always;
由系统自动生成每页html代码,每页由<div>块并列组成
每个<div>块,不能被嵌套在其他<div>之中
部分代码如下
<div id="Page1" style="display:block;" class="page_content">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin:auto;border-collapse: collapse;table-layout:fixed;">
<tbody>
<!--内容省略 -->
</tbody>
</table>
</div>
<div id="Page2" style="page-break-before:always;display:block;" class="page_content">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin:auto;border-collapse: collapse;table-layout:fixed;">
<tbody>
<!--内容省略 -->
</tbody>
</table>
</div>
实现页面分页打印是很多小伙伴们都想知道的,那么你知道web如何实现页面分页打印的具体方法吗?下面就让爱站小编带领大家一起去学习学习吧,希望本文对你有所帮助。
1.首先引入一个WebBrowser在需要打印的页面,可以直接添加:
?
?
?
到页面,或者使用JavaScript在需要的时候临时添加也可以:
?
?
?
document.body.insertAdjacentHTML("beforeEnd",
"
classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");
2 .页面设置和打印预览
如下所示,直接调用即可
?
?
?
document.all.WebBrowser.ExecWB(6,6) 直接打印
document.all.WebBrowser.ExecWB(8,1) 页面设置
document.all.WebBrowser.ExecWB(7,1) 打印预览
或者:
?
?
?
execScript("document.all.WebBrowser.ExecWB 7, 1","VBScript");
3 隐藏不打印的页面元素和分页
CSS 有个Media 属性,可以分开设置打印和显示的格式。
如 中间的格式将只在打印时起作用,不会影响显示界面。
所以可以设定
.Noprint{display:none;}
.PageNext{page-break-after: always;}
然后给不想打印的页面元素添加: class="Noprint" ,那就不会出现在打印和打印预览中了。
想分页的地方添加:
4.打印页面的特定部分
通过将需要打印的特定部分另建一个页面,然后装入主页面的一个IFrame中,再调用IFrame的打印方法,只打印IFrame中的内容实现的。
如:
下面的pringFrame js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId);
?
?
?
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": execScript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}
if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") ))
{
execOnFinish();
return;
}
var eventScope = printGetEventScope(frame);
var focused = document.activeElement;
window.printHelper = function() {
execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
printFireEvent(frame, eventScope, "onafterprint");
printWB.outerHTML = "";
execOnFinish();
window.printHelper = null;
}
document.body.insertAdjacentHTML("beforeEnd",
"
classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
// helpers
function printIsNativeSupport() {
var agent = window.navigator.userAgent;
var i = agent.indexOf("MSIE ")+5;
return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}
function printFireEvent(frame, obj, name) {
var handler = obj[name];
switch ( typeof(handler) ) {
case "string": frame.execScript(handler); break;
case "function": handler();
}
}
function printGetEventScope(frame) {
var frameset = frame.document.all.tags("FRAMESET");
if ( frameset.length ) return frameset[0];
return frame.document.body;
}
Iframe中所装载页面的打印效果在所装载页面设置就可以了,如分页等。
5.后台打印
通过建一个隐藏Iframe实现的,当然仍然会有页面装载的过程。
下面的函数创建Iframe装载页面并打印。如 printHidden(url) //url为页面地址
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"");
var doc = printHiddenFrame.document;
doc.open();
doc.write("
");doc.write("
url + "\">
");doc.write("");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete ) window.onprintcomplete();
}
printFrame(printHiddenFrame.printMe, onfinish);
}
它用到了printFrame,所以别忘了引用前面的函数。
以下为demo:
报表classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0"
width="0">
.Noprint{display:none;}
.PageNext{page-break-after: always;}
οnclick="document.all.WebBrowser.ExecWB(6,6)">
οnclick="document.all.WebBrowser.ExecWB(8,1)">
οnclick="document.all.WebBrowser.ExecWB(7,1)">
οnclick="printHidden(FrameId)">
1
2
height="30%" src="2.html">
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": execScript(onfinish); break;
case "function": onfinish();
}
if ( focused && !focused.disabled ) focused.focus();
}
if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") ))
{
execOnFinish();
return;
}
var eventScope = printGetEventScope(frame);
var focused = document.activeElement;
window.printHelper = function() {
execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
printFireEvent(frame, eventScope, "onafterprint");
printWB.outerHTML = "";
execOnFinish();
window.printHelper = null;
}
document.body.insertAdjacentHTML("beforeEnd",
"
classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
// helpers
function printIsNativeSupport() {
var agent = window.navigator.userAgent;
var i = agent.indexOf("MSIE ")+5;
return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}
function printFireEvent(frame, obj, name) {
var handler = obj[name];
switch ( typeof(handler) ) {
case "string": frame.execScript(handler); break;
case "function": handler();
}
}
function printGetEventScope(frame) {
var frameset = frame.document.all.tags("FRAMESET");
if ( frameset.length ) return frameset[0];
return frame.document.body;
}
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"");
var doc = printHiddenFrame.document;
doc.open();
doc.write("
");doc.write("
url + "\">
");doc.write("");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete ) window.onprintcomplete();
}
printFrame(printHiddenFrame.printMe, onfinish);
}
以上就是小编介绍web如何实现页面分页打印的内容,想要学习的朋友们,赶快把这篇内容收入囊中吧!?
原文链接:https://js.aizhan.com/develop/JavaScript/11536.html
如有疑问请与原作者联系
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有