ie print

Recently, making a small program requires precise location control of Web printing. IE's own printing function is basically half-crippled, unable to customize paper, unable to print directly, and due to the settings of the browser version or the operating system itself, even the most There will be problems with basic margin settings. In short, printing has become the biggest problem for Web programs. Therefore, using ActiveX controls to print is the best solution. Two, one is that the windows system itself has the WebBrowser.ExecWB control, but this one is not very flexible due to the limitation of the system's security settings, and the other is to use the third-party control ScriptX (http://www.meadroid.com /scriptx/), the basic functions of ScriptX are free, but the advanced functions are charged. Below I will summarize the recent experience of using ScriptX in the project. For more details, you can check the official manual: http://www.meadroid.com/scriptx/docs/printdoc.htm 


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>    

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033997&siteId=291194637