第三方打印控件:ScriptX
ScriptX 插件下载地址:
http://scriptx.meadroid.com/home.aspx
官方手册:
http://www.meadroid.com/scriptx/docs/printdoc.asp
ScriptX.cab打印代码(有弹出页面设置窗口)
<!--前提为必须设置了打印机,即为有默认的打印机,否则此页的弹出窗口不会显示--> <!--media=print 这个属性可以在打印时有效,设置打印时,打印按钮不显示的样式--> <style media=print> .Noprint{display:none;} .PageNext{page-break-after: always;} </style> <!--添加打印组件,注意设置codebase路径--> <object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="ScriptX.cab#Version=6,2,433,14"> </object> <!--calss="noprint"设置打印时不显示打印按钮--> <td class="noprint" align="right"><img src="" align="right" style="cursor:hand"onClick="set_print()"></td> <!--此方法为载入页面时,即弹出页面设置窗口--> <!--以下为常用打印设置--> <script defer="defer"> function window.onload() { factory.printing.printer = "HP DeskJet 870C" factory.printing.paperSize = "B%" factory.printing.paperSource = "Manual feed" factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页" factory.printing.footer = "(自定义页脚)" factory.printing.portrait = false factory.printing.leftMargin = 11 factory.printing.topMargin = 1.5 factory.printing.rightMargin = 0.75 factory.printing.bottomMargin = 1.5 factory.printing.PageSetup() ; //打印设置 factory.printing.Preview() ; //打印预览 } </script>
smsx.cab打印页代码(没有弹出页面设置窗口)
<object id="factory" viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="<%=path%>/erpxtbg/tjfx/smsx.cab#Version=6,3,434,26"></object> <style> @media print { .noprint {display:none} } .STYLE2 { font-size: 18px; font-weight: bold; } </style> <td class="noprint" align="right"><img src="" align="right" style="cursor:hand"onClick="set_print()"></td> <script language="javascript"> function set_print() { factory.printing.header = ""; factory.printing.footer = ""; factory.printing.portrait = 1; //1为纵向打,0为横向打 factory.printing.leftMargin = 13; //左边距 factory.printing.topMargin = 20; //右边距 factory.printing.Print(false); } </script>
备注一些常用的javascript功能控制:
<script defer> // -------------------基本功能,可免费使用----------------------- 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";//如为网络打印机,则需要进行字符转义 factory.printing.paperSize = "A4";//指定使用的纸张 factory.printing.paperSource = "Manual feed";//进纸方式,这里是手动进纸 factory.printing.copies = 1;//打印份数 factory.printing.printBackground = false;//是否打印背景图片 factory.printing.SetPageRange(false, 1, 3); //打印1至3页 //---------------------常用函数-------------------------------- factory.printing.Print(false);//无确认打印,true时打印前需进行确认 //factory.printing.Print(false, pageFrame); pageFrame为Iframe或Frame框架名称,只打印框架内容 factory.printing.PrintSetup();//打印设置 factory.printing.Preview();//打印预览 factory.printing.WaitForSpoolingComplete();//等待上一个打印任务完全送入打印池,在连续无确认打印时非常有用 factory.printing.EnumPrinters(index);//枚举已安装的所有打印机,主要用于生成打印机选择功能 </script>