网页控制打印条码

  网页控制打印条码.我在网上找到了两种方法.

    第一种:前提,条码打印机可以使用EPL语言.例子如下.

http://blog.csdn.net/peiyu_peiyu/article/details/8204164

  第二种:1.通过JQuery-barcode生成条形码图片.

    2.去除页眉以及页脚.

           2.使用js提取这部分的内容.

           3.打印. 这需要自己调整打印机设置,以及页面设置.

 

<html>
<head>
//引入 jquery 以及 jquery.barcode.0.3.js
<
script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.barcode.0.3.js"></script> <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(){ try{ var RegWsh = new ActiveXObject("WScript.Shell"); hkey_key="header"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); hkey_key="footer"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); }catch(e){} } //设置网页打印的页眉页脚为默认值 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){} } function doPrint() { bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--endprint-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); } </script> <style type="text/css"> #bcTarget{ width:6.5cm; height:1.2cm; } #num{ width:6.5cm; height:0.8cm; text-align : center; } #pnum{ } </style> </head> <body> <div> <!--startprint--> <div id="bcTarget">HG12345678</div> <div id="num"></div> <!--endprint--> </div> <input type="button" onclick='$("#num").append($("#bcTarget").html());$("#bcTarget").barcode("code39",{barWidth:2, barHeight:30});' value="ean13"> <input type="button" value="清空页码" onclick=pagesetup_null()> <input type="button" value="恢复页码" onclick=pagesetup_default()> <input type="button" onclick="doPrint()" value="打印"/> </body> <html>

 

 

posted @ 2013-08-16 13:47  Lets飞跃  阅读(1005)  评论(1)    收藏  举报