Simple to use:
Introduce controls in the page head:
<style media=print> .PageNext{page-break-after: always;} .Noprint{display:none;} </style>
Set printing parameters:
// -------------------Basic function, free to use ----------------------- factory.printing.header = "";//页眉 factory.printing.footer = "";//footer factory.printing.SetMarginMeasure(1);//Margin unit, 1 is mm, 2 is inch//margin setting, it should be noted that most printers cannot print with zero margins, that is, there is a minimum margin , generally more than 6 mm//When setting the margin, if it is set to zero, it will be automatically adjusted to its minimum margin factory.printing.leftMargin = 7;//Left margin factory.printing.topMargin = 7;//Top margin factory.printing.rightMargin = 7;//Right Margin factory.printing.bottomMargin = 7;//Bottom margin factory.printing.portrait = true;//Whether to print vertically, false horizontally //--------------------Advanced Features-------------------------- ------------------- factory.printing.printer = "EPSON LQ-1600KIII";//Specify the printer used //factory.printing.printer = "\\\\cosa-data\\HPLaserJ";//If it is a network printer, character escaping is required
factory.printing.paperSize = "A4";//Specify the paper used factory.printing.paperSource = "Manual feed";//Paper feeding method, here is manual feeding factory.printing.copies = 1;//Number of copies to print factory.printing.printBackground = false;//Whether to print the background image factory.printing.SetPageRange(false, 1, 3); //Print 1 to 3 pages //----------------------Common functions------------------------- ------- factory.printing.Print(false);//Print without confirmation, if true, you need to confirm before printing factory.printing.PrintSetup();//Print setup factory.printing.Preview();//Print preview factory.printing.WaitForSpoolingComplete();//Wait for the last print task to be completely sent to the print pool, which is very useful when printing continuously without confirmation factory.printing.EnumPrinters(index);//Enumerate all installed printers, mainly used to generate printer selection function
<html> <head> <title> ScriptX使用 </title> <script language="javascript"> //isZong: whether to print vertically isSelectPrinter: whether to select a printer, false to print directly with the default printer function printit(isZong, isSelectPrinter) { try { xprint.printing.portrait = isZong;//true is vertical, false is horizontal xprint.printing.footer = "footer";//footer xprint.printing.header = "Header";//Header xprint.printing.leftMargin =0.5;//左 xprint.printing.topMargin = 0.5;//上 xprint.printing.rightMargin = 0.5;//右 xprint.printing.bottomMargin = 0.5;//下 //xprint.printing.PageSetup(); //Pop up the print setup window //xprint.printing.Preview(); //Pop up the print preview window xprint.printing.Print(isSelectPrinter); //Whether to pop up the printer selection page } catch(e) { alert('No default print device is set'); } } </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> print test hahaha <input type="button" value="直接" onclick="printit(true, false)" /> <input type="button" value="不直接" onclick="printit(false, true)" /> </body> </html>