日期:2014-05-16  浏览次数:20489 次

js 连接打印机 分页打印案列
下面是我做的一个分页打印效果:,不过只适应在IE下使用。
<html><head><title>[打印时间:2013-3-14 17:20:58]</title>
 <link href="/css/print.css" rel="stylesheet" type="text/css"> 
<!--media=print 这个属性可以在打印时有效--> 
<style media="print"> 
.Noprint{display:none;} 
.PageNext{page-break-after:always;} 
</style>
<script language="javascript">
 var hkey_root,hkey_path,hkey_key; hkey_root='HKEY_CURRENT_USER'; hkey_path='\\Software\\Microsoft\\Internet Explorer\\PageSetup\\'; 
function pagesetup_null_head() {
try{ var RegWsh = new ActiveXObject('WScript.Shell');
     hkey_key = 'header'; RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '');} catch (e) {showErr('页面设置');}} 
function pagesetup_null_footer() {
     try{ 
         var RegWsh = new ActiveXObject('WScript.Shell');
         hkey_key = 'footer'; 
         RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '');
        } catch (e) {
         showErr('页面设置');}
        } 
function pagesetup_default() {
         try {
         var RegWsh = new ActiveXObject('WScript.Shell'); 
         hkey_key = 'header'; 
         RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '&w&b页码,&p/&P'); hkey_key = 'footer'; 
       RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, '&u&b&d');
        } catch (e) {showErr('页面设置');}} 
function showErr(operation){alertMsg.info('对不起!您目前无法通过此按钮进行“'+operation+'”!\n\n请您直接使用浏览器自带的菜单进行“'+operation+'”;\n\n或者将IE浏览器开启ActiveX后再试试:\n\n开启ActiveX步骤:\nIE浏览器:工具->Internet选项->安全->“Internet”和“本地Intranet”->自定义级别:ActiveX控件和插件->对没有标记为安全的ActiveX控件进行初始化和脚本运行:设置为“启用”。(或者将ActiveX控件和插件->所有与ActiveX相关的参数都设置为“启用”。)\n\n以上设置确定后,再重新登录UTMS,即可进行“'+operation+'”。');} 
function printView(){try{document.all.WebBrowser.ExecWB(7,1)}catch(e){showErr('打印预览');};} 
function toPrint(){if (confirm('您确定打印了吗?')){window.print();	alertMsg.info('正在打印中,请您稍候……\n\n打印完成后请您按确定返回。');}}  function pageSetup(){try{document.all.WebBrowser.ExecWB(8,1)}catch(e){showErr('页面设置');};}</script>
</head>
<body oncontextmenu="alertMsg.info(&quot;欢迎使用UTMS打印页面~&quot;);return false;">
<object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="WebBrowser" width="87" height="21">
</object>
<div style="text-align:center">
<div id="batchPrintMatesReceipt">
    
	<div>
	    <div>
		    <table width="100%" style="border-collapse:collapse;">
			    <thead>
			       <tr height="20px">
				        <td colspan="6" align="center" style="font-size:15pt">
				         <!-- 	<b>广州中邮普泰移动通信设备有限责任公司</b> -->
					     <b style="line-height: 22px;">中国移动通信集团终端有限公司广东分公司</b>
				        </td>
			       </tr>
			    </thead>
			    <tbody>
			        <tr height="20px">
				        <td colspan="5" width="55%">
					        <table width="100%">
						        <tbody><tr>
							      <td align="right" style="font-size:12pt;"> <b style="line-height: 18px;">送&nbsp;&nbsp;&nbsp;&nbsp;货&nbsp;&nbsp;&nbsp;&nbsp;单</b> </td>
						        </tr>
					        </tbody></table>
					
				        </td>
				        <td align="center" style="font-size:10pt">
					     <font style="line-height: 15px;">送货单号:TH-ZDJM-1300026</font>
				        </td>
			        </tr>
			        <tr height="20px">
				        <td colspan="6" width="100%">
					        <table width="100%">
						        <tbody><tr>
							       <td width="50%" style="font-size:10pt"><font style="line-height: 15px;">客户名称:终端公司广州省仓</font></td>
							       <td style="font-size:10pt"><font style="line-height: 15px;">收货地址:</font></td>
							    </tr>
					        </tbody></table>
				        </td>