This article mainly shares with you an example of javaScript linking to a printer and printing receipts. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
As shown below:
<!-- <!DOCTYPE html> --> <meta> <script></script> <script></script> <script></script> <script> function doPrint(){ bdhtml=window.document.body.innerHTML; sprnstr="<!--startprint-->"; eprnstr="<!--b-->"; prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); window.document.body.innerHTML=prnhtml; window.print(); top.layer.closeAll(); } function closes (){ top.layer.closeAll(); } function downPdf(){ document.getElementById("dayin").style.display = "none"; document.getElementById("baocun").style.display = "none"; html2canvas(document.body, { onrendered:function(canvas) { var contentWidth = canvas.width; var contentHeight = canvas.height; //一页pdf显示html页面生成的canvas高度; var pageHeight = contentWidth / 592.28 * 841.89; //未生成pdf的html页面高度 var leftHeight = contentHeight; //pdf页面偏移 var position = 0; //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高 var imgWidth = 595.28; var imgHeight = 592.28/contentWidth * contentHeight; var pageData = canvas.toDataURL('image/jpeg', 1.0); var pdf = new jsPDF('', 'pt', 'a4'); //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89) //当内容未超过pdf一页显示的范围,无需分页 if (leftHeight < pageHeight) { pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight ); } else { while(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 = ""; } </script> <p> <button><i></i>打印</button> <button><i></i>保存</button> </p> <!--startprint--> <br> <p> </p>
新XXXXX物业服务中心 | ||||||
收费单据 | ||||||
收票类型:电费 | 缴费日期: | ${emfee.dt} | ||||
户名 | ${emfee.userName} | 表号 | ${emfee.emNo} | 房号 | ${emfee.num} | |
起止时间 | ${emfee.emDt}至${emfee.startDt} | 缴费金额 | ${emfee.tranMoney} | 倍率 | ${emfee.emRate} | |
用电量 | 时段 | 起止表码 | 倍率前用量 | 本次用量 | 单价 | 本次电费 |
尖 | ${emfee.mosaicJian} | ${emfee.jianQuantity} | ${emfee.blJian} | ${emfee.jian} | ${emfee.jianFee} | |
峰 | ${emfee.mosaicFeng} | ${emfee.fengQuantity} | ${emfee.blFeng} | ${emfee.feng} | ${emfee.fengFee} | |
平 | ${emfee.mosaicPing} | ${emfee.pingQuantity} | ${emfee.blPing} | ${emfee.ping} | ${emfee.pingFee} | |
谷 | ${emfee.mosaicGu} | ${emfee.guQuantity} | ${emfee.blGu} | ${emfee.gu} | ${emfee.guFee} | |
总 | ${emfee.mosaicZong} | ${emfee.quantity} | ${emfee.blquantity} | —— | ${emfee.electFee} | |
电费 | 上次剩余(元) | 本期已用(元) | 本次缴费(元) | 本次剩余(元) | ||
${emfee.lastRemainQ} | ${emfee.electFee} | ${emfee.tranMoney} | ${emfee.remainQ} | |||
收款人: | 付款人: |
Related recommendations:
javascript print page code_javascript skills
javascript Summary of printing content methods_javascript skills
js client printing html how to remove the header and footer
JavaScript loop practice method of printing triangles, factorials, and multiplication tables
The above is the detailed content of javaScript connects to printer and prints receipt example sharing. For more information, please follow other related articles on the PHP Chinese website!

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
