使用ScriptX控件进行Web打印

 转自 [转]使用ScriptX控件进行Web打印总结

       最近项目需要实现B/S架构的套打功能,这需要精确调整页面位置,并且最好能自动设置页边距,因此使用ActiveX控件打印是最好的解决方案,目前免费的选择考虑了其中两种,一是windows系统本身带有WebBrowser.ExecWB控件,但这个由于系统的安全设置方面的限制,需要客户端调整安全级别,这样客户容易反;,二是使用第三方的控件ScriptX(http://www.meadroid.com/scriptx/),ScriptX基本功能免费,但高级功能是收费的,下面我就把最近在项目中使用ScriptX的经验总结一下。更多细节您可以查看官方手册:http://www.meadroid.com/scriptx/docs/printdoc.htm  

简单使用:
在页面head中引入控件:

Html代码   收藏代码
  1. <style media=print>  
  2.  .PageNext{page-break-after: always;}  
  3.  .Noprint{display:none;}   
  4.  </style>  

 
设置打印参数:

Html代码   收藏代码
  1. // -------------------基本功能,可免费使用-----------------------  
  2. factory.printing.header = &quot;&quot;;//页眉  
  3. factory.printing.footer = &quot;&quot;;//页脚  
  4. factory.printing.SetMarginMeasure(1);//页边距单位,1为毫米,2为英寸//边距设置,需要注意大部分打印机都不能进行零边距打印,即有一个边距的最小值,一般都是6毫米以上//设置边距的时候时候如果设置为零,就会自动调整为它的最小边距  
  5.   
  6. factory.printing.leftMargin = 7;//左边距  
  7. factory.printing.topMargin = 7;//上边距  
  8. factory.printing.rightMargin = 7;//右边距  
  9. factory.printing.bottomMargin = 7;//下边距  
  10. factory.printing.portrait = true;//是否纵向打印,横向打印为false  
  11.   
  12.   
  13. //--------------------高级功能---------------------------------------------  
  14. factory.printing.printer = &quot;EPSON LQ-1600KIII&quot;;//指定使用的打印机  
  15. //factory.printing.printer = &quot;\\\\cosa-data\\HPLaserJ&quot;;//如为网络打印机,则需要进行字符转义  
Html代码   收藏代码
  1. factory.printing.paperSize = &quot;A4&quot;;//指定使用的纸张  
  2.   
  3. factory.printing.paperSource = &quot;Manual feed&quot;;//进纸方式,这里是手动进纸  
  4. factory.printing.copies = 1;//打印份数  
  5.   
  6. factory.printing.printBackground = false;//是否打印背景图片  
  7. factory.printing.SetPageRange(false, 1, 3); //打印1至3页  
  8.   
  9. //---------------------常用函数--------------------------------  
  10. factory.printing.Print(false);//无确认打印,true时打印前需进行确认  
  11. factory.printing.PrintSetup();//打印设置  
  12. factory.printing.Preview();//打印预览  
  13. factory.printing.WaitForSpoolingComplete();//等待上一个打印任务完全送入打印池,在连续无确认打印时非常有用  
Html代码   收藏代码
  1. factory.printing.EnumPrinters(index);//枚举已安装的所有打印机,主要用于生成打印机选择功能  

 

如:

 

html代码  
  1. <html>    
  2. <head>    
  3. <title> ScriptX使用 </title>    
  4.     
  5. <script language="javascript">    
  6.     //isZong:是否纵向打印   isSelectPrinter:是否选择打印机,false直接使用默认打印机打印    
  7.     function printit(isZong, isSelectPrinter) {    
  8.         try {    
  9.             xprint.printing.portrait = isZong;//true为纵向,false为横向    
  10.             xprint.printing.footer = "页脚";//页脚    
  11.             xprint.printing.header = "页眉";//页眉    
  12.             xprint.printing.leftMargin =0.5;//左    
  13.             xprint.printing.topMargin = 0.5;//上    
  14.             xprint.printing.rightMargin = 0.5;//右    
  15.             xprint.printing.bottomMargin = 0.5;//下    
  16.     
  17.             //xprint.printing.PageSetup(); //弹出打印设置窗口     
  18.             //xprint.printing.Preview(); //弹出打印预览窗口     
  19.     
  20.             xprint.printing.Print(isSelectPrinter); //是否弹出打印机选择页面    
  21.          } catch(e) {    
  22.                 alert('没有设置默认打印机件');    
  23.         }    
  24.     }    
  25. </script>    
  26.         
  27. </head>    
  28.     
  29. <body>    
  30.     <object id="xprint" style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="smsx.cab#version=6,5,439,72"></object>    
  31.     
  32. 打印测试哈哈哈    
  33.     
  34. <input type="button" value="直接" onclick="printit(true, false)" />    
  35. <input type="button" value="不直接" onclick="printit(false, true)" />    
  36. </body>    
  37. </html>    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值