Skip to content

Instantly share code, notes, and snippets.

@tresf
Created February 2, 2023 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tresf/dc922a16e0f56519e975a3e26315ea56 to your computer and use it in GitHub Desktop.
Save tresf/dc922a16e0f56519e975a3e26315ea56 to your computer and use it in GitHub Desktop.
QZ Tray + ThermalPrinterEncoder (Node.js)
let tpe = require('thermal-printer-encoder');
let ws = require('ws');
let qz = require('qz-tray');
let encoder = new tpe({
language: 'esc-pos'
});
let result = encoder
.initialize()
.text('The quick brown fox jumps over the lazy dog')
.newline()
.qrcode('https://nielsleenheer.com')
.encode();
let config = qz.configs.create("Epson TM-T88VI");
let data = [{
type: 'raw',
format: 'command',
flavor: 'hex',
data: Buffer.from(result).toString('hex')
}];
qz.api.setWebSocketType(ws);
qz.websocket.connect().then(() => {
return qz.print(config, data);
}).catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment