本文介绍了电子收据热敏打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种使用电子的javascript打印收据的方法.我已经尝试过 QZ-TRAY ,但是由于Electron,它不起作用.我还尝试过 node-thermal-printer (节点热敏打印机),但它也对我没有用.这里有没有人知道如何在不使用javascript(Electron)询问用户的情况下打印收据?

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)?

编辑

Qz托盘提供了一个非常好的解决方案,而且很难被击败.

Qz-tray offer a solution that is pretty good and hard to beat.

如果您遇到错误 RSVP未定义,则需要在此行中启用本机Javascript Promise.

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));

推荐答案

引用相关评论...

"对于QZ,花了整个20秒钟才找到它: https://qz.io/wiki/2.0-api-override "

"for QZ it took all of 20secs to find this: https://qz.io/wiki/2.0-api-override"

发布评论作为解决方案,以解决问题.感谢@ gilbert-gabriel的帮助.

Posting as asolution as the comments suggest it worked. Credits to @gilbert-gabriel for the help.

默认情况下,RSVP承诺已启用,但通过以下方式支持本机JS承诺:

The RSVP promises are enabled by default, but native JS promises are supported via:

qz.api.setPromiseType(resolver => new Promise(resolver));

更全面的示例:

// 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));

这篇关于电子收据热敏打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 00:58