使用ScriptX控件进行Web打印总结

来源:互联网 发布:博易大师mac版 编辑:程序博客网 时间:2024/06/11 17:48

转自:http://xiaofengtoo.iteye.com/blog/778863

第三方控件ScriptX:http://www.meadroid.com/scriptx/

官方手册:http://www.meadroid.com/scriptx/docs/printdoc.htm  

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

<style media=print> .PageNext{page-break-after: always;} .Noprint{display:none;}  </style>

设置打印参数:

// -------------------基本功能,可免费使用-----------------------factory.printing.header = "";//页眉factory.printing.footer = "";//页脚factory.printing.SetMarginMeasure(1);//页边距单位,1为毫米,2为英寸//边距设置,需要注意大部分打印机都不能进行零边距打印,即有一个边距的最小值,一般都是6毫米以上//设置边距的时候时候如果设置为零,就会自动调整为它的最小边距factory.printing.leftMargin = 7;//左边距factory.printing.topMargin = 7;//上边距factory.printing.rightMargin = 7;//右边距factory.printing.bottomMargin = 7;//下边距factory.printing.portrait = true;//是否纵向打印,横向打印为false//--------------------高级功能---------------------------------------------factory.printing.printer = "EPSON LQ-1600KIII";//指定使用的打印机//factory.printing.printer = "\\\\cosa-data\\HPLaserJ";//如为网络打印机,则需要进行字符转义

完整示例:

<html>  <head>  <title> ScriptX使用 </title>    <script language="javascript">      //isZong:是否纵向打印   isSelectPrinter:是否选择打印机,false直接使用默认打印机打印      function printit(isZong, isSelectPrinter) {          try {              xprint.printing.portrait = isZong;//true为纵向,false为横向              xprint.printing.footer = "页脚";//页脚              xprint.printing.header = "页眉";//页眉              xprint.printing.leftMargin =0.5;//左              xprint.printing.topMargin = 0.5;//上              xprint.printing.rightMargin = 0.5;//右              xprint.printing.bottomMargin = 0.5;//下                //xprint.printing.PageSetup(); //弹出打印设置窗口               //xprint.printing.Preview(); //弹出打印预览窗口                 xprint.printing.Print(isSelectPrinter); //是否弹出打印机选择页面           } catch(e) {                  alert('没有设置默认打印机件');          }      }  </script>        </head>    <body>      <object id="xprint" style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="smsx.cab#version=6,5,439,72"></object>    打印测试哈哈哈    <input type="button" value="直接" onclick="printit(true, false)" />  <input type="button" value="不直接" onclick="printit(false, true)" />  </body>  </html>  

相关资源:http://xiaofengtoo.iteye.com/blog/778863

0 1
原创粉丝点击