日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java实现分页打印功能_web 页面分页打印的实现

發布時間:2023/12/18 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java实现分页打印功能_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="NoprLvDXDjmKint" ,那就不會出現在打印和打印預覽中了。

想分頁的地方添加:

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-00http://www.cppcns.comC04FD705A2\">");

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 downloahttp://www.cppcns.comded 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 頁面分頁打印的實現

本文地址: http://www.cppcns.com/ruanjian/java/49234.html

總結

以上是生活随笔為你收集整理的java实现分页打印功能_web 页面分页打印的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。