Receipt thermal printer in Electron(Electron 收据热敏打印机)
问题描述
我需要找到一种在 Electron 的 javascript 中打印收据的方法.我已经尝试过 QZ-TRAY,但由于 Electron 无法正常工作.我也尝试过 node-thermal-printer,但它也从未对我有用.这里有人知道如何在不使用 javascript (Electron) 询问用户的情况下打印收据吗?
编辑
Qz-tray 提供了一个非常好的解决方案.
如果您遇到错误 RSVP 未定义
,您需要使用此行启用原生 javascript 承诺.
qz.api.setPromiseType(resolver => new Promise(resolver));
引用相关评论...
<块引用><块引用>对于 QZ,我的问题是 RSVP 未定义
,而对于 node-thermal-printer,打印机从未打印过."
对于 QZ,它花了 20 秒才找到这个:https://qz.io/wiki/2.0-api-override"
按照评论建议的方式发布解决方案.感谢@gilbert-gabriel 的帮助.
默认情况下启用 RSVP 承诺,但通过以下方式支持原生 JS 承诺:
qz.api.setPromiseType(resolver => new Promise(resolver));
一个更全面的例子:
//安装依赖:/*npm install qz-tray js-sha256*///提供 API 覆盖并开始与 QZ Tray 对话:从'qz-tray'导入*作为qz;从'js-sha256'导入{sha256};qz.api.setSha256Type(data => sha256(data));qz.api.setPromiseType(resolver => new Promise(resolver));qz.websocket.connect().then(qz.printers.getDefault).then(printer => console.log("默认打印机是:" + 打印机)).then(qz.websocket.disconnect).catch(err => console.error(err));
I need to find a way of printing receipts in javascript from Electron. I already tried QZ-TRAY but it doesn't work because of Electron. I also tried node-thermal-printer but it also never worked for me. Does anybody here know how you can print receipts without asking the user in javascript (Electron)?
EDIT
Qz-tray offer a solution that is pretty good and hard to beat.
If you have the error RSVP is not defined
you need to enable native javascript promises with this line.
qz.api.setPromiseType(resolver => new Promise(resolver));
Quoting the relevant comments...
"Well with QZ my problem was
RSVP is not defined
and with node-thermal-printer, the printer just never printed.""for QZ it took all of 20secs to find this: https://qz.io/wiki/2.0-api-override"
Posting as asolution as the comments suggest it worked. Credits to @gilbert-gabriel for the help.
The RSVP promises are enabled by default, but native JS promises are supported via:
qz.api.setPromiseType(resolver => new Promise(resolver));
A more comprehensive example:
// Install dependencies:
/*
npm install qz-tray js-sha256
*/
// Provide API overrides and start talking to QZ Tray:
import * as qz from 'qz-tray';
import { sha256 } from 'js-sha256';
qz.api.setSha256Type(data => sha256(data));
qz.api.setPromiseType(resolver => new Promise(resolver));
qz.websocket.connect()
.then(qz.printers.getDefault)
.then(printer => console.log("The default printer is: " + printer))
.then(qz.websocket.disconnect)
.catch(err => console.error(err));
这篇关于Electron 收据热敏打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Electron 收据热敏打印机
基础教程推荐
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 动态更新多个选择框 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01