WEB套打
来源:互联网 发布:java按键精灵 编辑:程序博客网 时间:2024/06/11 08:09
套打的页面不可能给用户看,需要单独制作一个套打的页面,只有要打印的内容,位置用<DIV style="LEFT: 35mm; FONT: 9pt 宋体; POSITION: absolute; TOP: 75mm">打印内容</DIV>其中,left 是你打印纸从最左边到内容的距离,top 是从纸最上边到打印内容的距离,这个距离要用尺量好,并且减去19.05,这个数是IE页面设置中页距的上下左右的默认值,不减就对不准了。
下面是在网上找到一个脚本,专门是用来调用套打页面的,并根据我的需要做了点改动。
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": alert('print... '); break;//execScript(onfinish)
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",
"<object id=/"printWB/" width=0 height=0 /
classid=/"clsid:8856F961-340A-11D0-A96B-00C04FD705A2/">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
function hideButton()
{
document.getElementById("btn_Back").style.display = "none";
}
function printFixedApp()
{
if(confirm('确定要打印吗?'))//这些是我自己加的,业务需要隐藏点过的按钮
{
document.getElementById("btn_Back").style.display = "none";
document.getElementById("btn_print").style.display = "none";
document.getElementById("btn_modify").style.display = "none";
printHidden("printPage_fixed.aspx");//里面是套打的页面
}
}
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"<iframe name=printHiddenFrame width=0 height=0></iframe>");
var doc = printHiddenFrame.document;
doc.open();
doc.write("<body onload=/"parent.onprintHiddenFrame()/">");
doc.write("<iframe name=printMe width=0 height=0 src=/"" +
url + "/"></iframe>");
doc.write("</body>");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete )
{
window.onprintcomplete();
alert("print completed!");
}
window.location.href = "ApplicationBillView_fixed.aspx";//打印完成后转到其它页
}
printFrame(printHiddenFrame.printMe, onfinish);
}
// 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;
}
window.print = printFrame;
// main stuff
function printFrame(frame, onfinish) {
if ( !frame ) frame = window;
function execOnFinish() {
switch ( typeof(onfinish) ) {
case "string": alert('print... '); break;//execScript(onfinish)
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",
"<object id=/"printWB/" width=0 height=0 /
classid=/"clsid:8856F961-340A-11D0-A96B-00C04FD705A2/">");
printFireEvent(frame, eventScope, "onbeforeprint");
frame.focus();
window.printHelper = printHelper;
setTimeout("window.printHelper()", 0);
}
function hideButton()
{
document.getElementById("btn_Back").style.display = "none";
}
function printFixedApp()
{
if(confirm('确定要打印吗?'))//这些是我自己加的,业务需要隐藏点过的按钮
{
document.getElementById("btn_Back").style.display = "none";
document.getElementById("btn_print").style.display = "none";
document.getElementById("btn_modify").style.display = "none";
printHidden("printPage_fixed.aspx");//里面是套打的页面
}
}
function printHidden(url) {
document.body.insertAdjacentHTML("beforeEnd",
"<iframe name=printHiddenFrame width=0 height=0></iframe>");
var doc = printHiddenFrame.document;
doc.open();
doc.write("<body onload=/"parent.onprintHiddenFrame()/">");
doc.write("<iframe name=printMe width=0 height=0 src=/"" +
url + "/"></iframe>");
doc.write("</body>");
doc.close();
}
function onprintHiddenFrame() {
function onfinish() {
printHiddenFrame.outerHTML = "";
if ( window.onprintcomplete )
{
window.onprintcomplete();
alert("print completed!");
}
window.location.href = "ApplicationBillView_fixed.aspx";//打印完成后转到其它页
}
printFrame(printHiddenFrame.printMe, onfinish);
}
// 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;
}
- web打印、套打
- WEB套打
- web 套打
- web打印+套打问题
- Web套打方案集锦
- 利用ASP.NET实现web套打
- 基于web的套打实现方案
- 通用套打web端解决方法
- 利用ASP.NET实现web套打
- 解决Jasperreport的web 套打
- 基于Web的套打方案分析
- js实现WEB套打程序
- 解决Jasperreport的web 套打
- WEB套打程序开发 (lodop使用)
- 套打
- 套打
- js实现web上的word凭据套打
- Web、winform打印、批量打印解决方案、excel套打模板
- OpenCV WinCE/WM移植
- 在hibernate中实现oracle的主键自增策略
- 启动画面、ico资源和系统快捷键
- 面向对象的扩展设计
- 索引器1
- WEB套打
- IPSec 关闭端口
- WebService CSF使用详解
- Introduction To Unix Signals Programming
- 使用 Apache Ant 和 Apache JMeter 频繁进行负载测试
- haslayout是什么意思
- state-对象行为型模式
- 看看谁是最流行的Linux Web服务器谈CentOS
- 在Delphi 7 中构建即时通讯服务端和客户端构架方案