scriptX进行web打印

先直接来个简单DEMO,给大家提提神,可以照搬

<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>scritpX_DEMO</title>
<style type="text/css" media="print">
    .noprint{
        display: none
    }
</style>
<script type="text/javascript">
   function window.onload(){   
        document.getElementById('idPrint1').disabled = false; //enable UI button      
        document.getElementById('idPrint2').disabled = false;      
        document.getElementById('idPrint3').disabled = false;      
        document.getElementById('idPrint4').disabled = false;
       // factory.printing.paperSize = "A4"      
        factory.printing.header = ""      
        factory.printing.footer = ""     
        factory.printing.portrait = true;    
        factory.printing.leftMargin = 0.75      
        factory.printing.topMargin = 1.5      
        factory.printing.rightMargin = 0.75      
        factory.printing.bottomMargin = 1.5      
        }    
</script>
</head>
<body>
    <object id=factory viewastext style="display: none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814">
    </object>
    
    <div class="noprint" style="text-align: center">
        <input id="idPrint1" type="button" value="打印本页" onclick="factory.printing.Print(false)" class="mybutton">
        <input id="idPrint2" type="button" value="页面设置" onclick="factory.printing.PageSetup()" class="mybutton">
        <input id="idPrint3" type="button" value="打印预览" onclick="factory.printing.Preview()" class="mybutton">
        <input id="idPrint4" type="button" onclick="javascript:window.close()" value="关闭窗口" class="mybutton">
    </div>
    
    <span>我是打印的内容:测试web打印</span>

    <span class="noprint">我不是打印的内容</span>

</body>
</html>

参数解释

// -------------------基本功能,可免费使用-----------------------
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(false13); //打印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);//枚举已安装的所有打印机,主要用于生成打印机选择功能
 

猜你喜欢

转载自blog.csdn.net/alspd_zhangpan/article/details/79477276