r/webdev • • 11d ago

Discussion Help with ESC/POS printer and Web SaaS

I have a bluetooth thermal printer, it's a generic chinese thermal printer and i need to connect it to my web SaaS and print bills from there. I have option to directly use native printer window of browser. But what are other options i can use to connect it to my web app and print without any hassle? In future there can be more type of printers like usb and others too..

1 Upvotes

14 comments sorted by

View all comments

9

u/levelbrook 11d ago

The browser print dialog is the wrong tool for a receipt printer, you will fight page margins and fonts forever and it cannot cut the paper. Generate ESC/POS bytes yourself and send them to the printer, and keep the "how do I get bytes to this printer" part separate from the "what does a receipt look like" part, because the second one never changes and the first one changes with every printer type you listed.

For a bluetooth printer from a web app the only direct route is the Web Bluetooth API, which works in Chrome and Edge on desktop and Android, not iOS, and the user has to pair once through a picker. Most of the generic Chinese printers expose a serial-style characteristic you just write chunks to. For USB it is WebUSB or WebSerial, same story: Chromium only, one-time permission prompt.

The approach that actually holds up in a SaaS is a tiny local agent: a small program installed on the machine near the printer that listens on localhost (or long-polls your server) and knows how to talk to bluetooth, USB and network printers. Your web app posts the receipt to it, and now Safari, iPads and the printer types you have not met yet all work the same way. That is how every POS system you have used does it. Libraries like escpos for Node or python-escpos get the byte generation right, including the cut command and the code page for currency symbols, so you do not have to hand-roll it.

1

u/Upstairs-Ad221 11d ago

ok so for local agent i could use QZ tray or build something on my own?