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