ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 打印调用demo * 预览打印 ``` printer('<h1>test</h1>','-print-dialog','landscape,fit',e=>{ console.log(e) }) ``` * 最后的回调函数是可选的 可传入`null` * 参数一 htmlStr 打印内容 * 参数二 打印方式【三选一】 printType * 参数三 打印设置 printSettings ## 具体命令使用如下 ``` htmlStr 打印内容 打印方式【三选一】 printType -print-to-default : 将此命令行上指示的所有文件打印到系统默认打印机 -print-to <printer-name> : 将此命令行上指示的所有文件打印到指定的打印机 -print-dialog :显示此命令行上指示的所有文件的打印对话框。 打印设置 printSettings -print-settings <settings-list> 与-print-to 和 结合使用 -print-to-default 。允许在不使用“打印”对话框的情况下调整一些与打印相关的设置。设置列表是一个逗号分隔的页面范围和高级选项列表,例如 even 或 odd 。 portrait 或 landscape : 可以提供 90 度旋转内容(不是必须通过选择打印机默认值预先设置的纸张旋转) noscale , shrink 和 fit color 或者 monochrome duplex , duplexshort , duplexlong 和 simplex bin=<num or name> : 选择要打印到的纸盘 paper=<page size> : 页面大小为 A2 , A3 , A4 , A5 , A6 , letter , legal , tabloid , statement 例如, -print-settings "1-3,5,10-8,odd,fit,bin=2" 打印第1、3、5、9 页(即 1-3、5-5 和 10-8 范围内的奇数页)并缩放它们以使其适合纸张的可打印区域。 -print-settings "3x" : 打印文档 3 次 ``` ## 具体demo演示 * 批量连续打印与静默打印 ``` printer(`<div style="color:red;font-size:30px;">The title 111</div> <img style="width:85%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0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2IC05IC0yNSAtMjB6Ii8+CjwvZz4KPC9zdmc+Cg=="></img> <div class="pageT"></div> <div style="color:red;font-size:30px;">The title 222</div> <div>窗前明月光</div> <div>地上鞋两双</div> <img style="width:85%" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB3aWR0aD0iMjI0LjAwMDAwMHB0IiBoZWlnaHQ9Ijk4LjAwMDAwMHB0IiB2aWV3Qm94PSIwIDAgMjI0LjAwMDAwMCA5OC4wMDAwMDAiCiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCBtZWV0Ij4KCjxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAuMDAwMDAwLDk4LjAwMDAwMCkgc2NhbGUoMC4xMDAwMDAsLTAuMTAwMDAwKSIKZmlsbD0iIzAwMDAwMCIgc3Ryb2tlPSJub25lIj4KPHBhdGggZD0iTTAgNTgwIGMwIC0zOTMgMCAtNDAwIDIwIC00MDAgMjAgMCAyMCA3IDIwIDQwMCAwIDM5MyAwIDQwMCAtMjAgNDAwCi0yMCAwIC0yMCAtNyAtMjAgLTQwMHoiLz4KPHBhdGggZD0iTTYwIDU4MCBjMCAtMjYwIDQgLTQwMCAxMCAtNDAwIDcgMCAxMCAxNDAgMTAgNDAwIDAgMjYwIC0zIDQwMCAtMTAKNDAwIC02IDAgLTEwIC0xNDAgLTEwIC00MDB6Ii8+CjxwYXRoIGQ9Ik0xMjAgNTgwIGwwIC00MDAgMzAgMCAzMCAwIDAgNDAwIDAgND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OCAtOCA3IC0xMyAtNQotMTggLTIzIC04IC0yMSAtMjEgMyAtMjcgMjMgLTYgMjcgLTM1IDUgLTQzIC04IC00IC0yMiAtMSAtMzAgNiAtMjAgMTcgLTMyIDUKLTE1IC0xNSAyOCAtMzMgODggLTIgNzUgMzkgLTQgMTIgLTcgMzAgLTYgNDEgMSA0MSAtNDQgNjAgLTY5IDMweiIvPgo8cGF0aCBkPSJNMTY2OCAxMTkgYy0yMiAtMjMgLTIzIC0zMyAtMyAtMjUgMTIgNCAxNSAtNCAxNSAtNDQgMCAtMjggNSAtNTAgMTAKLTUwIDYgMCAxMCAzMCAxMCA3MCAwIDM5IC0zIDcwIC03IDY5IC01IDAgLTE2IC05IC0yNSAtMjB6Ii8+CjwvZz4KPC9zdmc+Cg=="></img> <style> @page { size: portrait; height:4cm; width:6cm; margin:0; } *{ padding:0; top:0; margin:0; text-align:center; font-family:SimHei; } /**分页符可用于批量无缝打印***/ .pageT{ page-break-after: always; } </style>`,'-print-to-default','landscape,fit',e=>{ console.log(e) }) ``` ### 对以上demo部分解释 * 设置纸张大小 单位可以是cm或mm ``` height:4cm; width:6cm; 或 height:40mm; width:60mm; 这是用于【60*40mm】的打印 ``` * 设置分页符 适用于批量无缝打印 ``` .pageT{ page-break-after: always; } ``` * 希望预览以上demo 将 第二位参数 `-print-to-default` 换为` -print-dialog`即可。以下为预览结果图 ![](https://img.kancloud.cn/56/6b/566b689ad3b0da2e42753e5b97238c8d_656x865.png) ## 注意事项 * 大量打印建议批量打印 并发调用可能会有异常的情况 * 条码后端生产 例如php 可通过输出svg格式条码到缓冲区并获取清空缓冲区 拿到svg字符串进行base64后放入img中拼接好前缀即可显示 * 对于更多高级的html css 打印用法可参考一下网址 * https://www.w3.org/TR/css-gcpm-3/ * https://developer.mozilla.org/zh-CN/docs/Web/CSS/@page * https://drafts.csswg.org/css-page-3/ * 对于绝大部分的html标签和css是支持的 但是也有很多不支持的或者需要新的方式替代 那么对最终显示样式不理想的 建议看一下调试日志 ### 调试与排查 * 需要在config.ini中设置`debug = False` 为 `debug = True` * 在安装目录中可查看`htmlPrint.log`文件中的日志 * 在调试完成后 一定要关闭调试模式 提高性能 * 如果出现预览正常 而打印不正常 不完整、乱码等情况 考虑是【乱码】驱动不对以及【不完整】打印可能是打印偏移量设置【水平偏移、垂直偏移】需要在驱动上进行设置 * 图像打印模糊不正常 需要【图形设置为无】 * 连续纸张或标签纸张都有不同设置 例如标签纸张有间距高 间距偏移等调整设置 具体联系厂家技术支持 * 如果遇到打印不清晰可能是字体问题 以上demo测试字体为`黑体SimHei` * 只要预览的没问题 大部分都是打印驱动设置问题 找厂家技术支持协调解决即可