Created
February 2, 2023 23:38
-
-
Save tresf/dc922a16e0f56519e975a3e26315ea56 to your computer and use it in GitHub Desktop.
QZ Tray + ThermalPrinterEncoder (Node.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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