javaScript 连接打印机,打印小票的实例
如下所示:
<%@pagecontentType="text/html;charset=UTF-8"%> <%@includefile="/webpage/include/taglib.jsp"%>functiondoPrint(){ bdhtml=window.document.body.innerHTML; sprnstr=""; eprnstr=""; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); top.layer.closeAll(); } functioncloses(){ top.layer.closeAll(); } functiondownPdf(){ document.getElementById("dayin").style.display="none"; document.getElementById("baocun").style.display="none"; html2canvas(document.body,{ onrendered:function(canvas){ varcontentWidth=canvas.width; varcontentHeight=canvas.height; //一页pdf显示html页面生成的canvas高度; varpageHeight=contentWidth/592.28*841.89; //未生成pdf的html页面高度 varleftHeight=contentHeight; //pdf页面偏移 varposition=0; //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高 varimgWidth=595.28; varimgHeight=592.28/contentWidth*contentHeight; varpageData=canvas.toDataURL('image/jpeg',1.0); varpdf=newjsPDF('','pt','a4'); //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89) //当内容未超过pdf一页显示的范围,无需分页 if(leftHeight 0){ pdf.addImage(pageData,'JPEG',0,position,imgWidth,imgHeight) leftHeight-=pageHeight; position-=841.89; //避免添加空白页 if(leftHeight>0){ pdf.addPage(); } } } pdf.save(document.getElementById("emNo").innerText+"("+document.getElementById("dt").innerText+').pdf'); } }) document.getElementById("baocun").style.display=""; document.getElementById("dayin").style.display=""; } 打印 保存
以上这篇javaScript连接打印机,打印小票的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。