标题: jatoolsPrint 打印类(转贴) [打印本页]
作者: admin 时间: 2009-11-12 11:39 标题: jatoolsPrint 打印类(转贴)
print.js
// JavaScript Document
function Print(){
this.printname="XP-58III";
}
Print.prototype.loadPrinter=function (){
var printers = jatoolsPrinter.getPrinters();
var f=0;
if(printers)
{
for (i=0;i< printers.length;i++){
if(printers==this.printname){
f=1;
break;
}
}
}
if(f==1){
return this.printname;
}else{
alert("没有找到打印机!");
return false;
}
}
Print.prototype.loadPapers=function (){
var printers = this.loadPrinter();
if(printers)
{
var papers = jatoolsPrinter.getPapers(printers)
if(papers)
{
for (i=0;i< papers.length;i++)
{
var name = papers.name;
var dimension = {
width:papers.width,
height:papers.height
};
paper_list.options=new Option(name, dimension);
}
}
}
}
Print.prototype.buildDoc=function (){
var printers = this.loadPrinter();
var myDoc = new Object();
if(printers){
var mysettings= new Object();
mysettings.printer=printers; // 指定打印机名称
mysettings.paperWidth = 58;
mysettings.paperHeight = 210;
mysettings.topMargin=5;
mysettings.bottomMargin=5;
mysettings.leftMargin=1;
mysettings.rightMargin=0;
mysettings.orientation = 1; // 指定打打印方向为纵向, 1/2 = 纵向/横向
myDoc.settings = mysettings;
//myDoc.marginIgnored=true; //设置零边距
myDoc.classesReplacedWhenPrint=new Array('.only_for_print{display:block}');
myDoc.documents =document;
myDoc.copyrights ='杰创软件拥有版权 www.jatools.com';
myDoc.done = function(err)
{
if(err){
alert(err);
}
}
return myDoc;
}else{
return false;
}
}
Print.prototype.doprint=function (how){
var myDoc = this.buildDoc();
// 调用打印方法
if(myDoc){
if(how == '打印预览...')
jatoolsPrinter.printPreview(myDoc); // 打印预览
else if(how == '打印...')
jatoolsPrinter.print(myDoc ,true); // 打印前弹出打印设置对话框
else
jatoolsPrinter.print(myDoc ,false); // 不弹出对话框打印
}
}
print.html
打印后关闭窗口
打印后关闭窗口查看源代码
admin 2009-10-3文档第一页dasdf
admin 2009-10-3文档第一页dasdf
原文: http://hi.baidu.com/aifang9999/b ... 49d844925807e8.html
欢迎光临 杰表技术论坛 (http://jatools.com/) |
Powered by Discuz! 6.1.0 |