Gil*_*iel 5 html javascript printing electron qz-tray
我需要找到一种从Electron用 javascript 打印收据的方法。我已经尝试过QZ-TRAY,但由于 Electron 无法正常工作。我也尝试过节点热敏打印机,但它也从未对我有用。这里有人知道如何在不使用 javascript (Electron) 询问用户的情况下打印收据吗?
编辑
Qz-tray 提供了一种非常好且难以击败的解决方案。
如果您遇到错误RSVP is not defined
,则需要使用此行启用本机 javascript 承诺。
qz.api.setPromiseType(resolver => new Promise(resolver));
引用相关评论...
“对于 QZ,我的问题是
RSVP is not defined
对于节点热敏打印机,打印机根本无法打印。”“对于 QZ 来说,花了 20 秒才找到这个: https: //qz.io/wiki/2.0-api-override ”
发布作为评论表明它有效的解决方案。感谢@gilbert-gabriel 的帮助。
默认情况下启用 RSVP Promise,但通过以下方式支持本机 JS Promise:
qz.api.setPromiseType(resolver => new Promise(resolver));
Run Code Online (Sandbox Code Playgroud)
一个更全面的例子:
// 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));
Run Code Online (Sandbox Code Playgroud)