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

转自: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="直接" οnclick="printit(true, false)" />  
<input type="button" value="不直接" οnclick="printit(false, true)" />  
</body>  
</html>  

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值