Live data from Hacker News

Writing a printer driver in JavaScript

kubesail.com

11–19 of 19 posts

Re: Writing a printer driver in JavaScript

#12

As someone who has spent an unfortunate amount of time working on shipping label software for ecommerce companies, my advice is to stay the hell away from ZPL. It's the layout language equivalent of C -- too many low-level footguns. Just send 4x6 PDF's to your thermal printer and be done with it. There are so many more tools, of much better quality, available for composing PDF's than you'll ever find for ZPL or other…

As someone who's dealt with these protocols as well I agree.

I find the print quality of PDFs perfect on Zebra's as long as you keep the following in mind:

  - Make sure the DPI of the document is correct (e.g. 203dpi)
  - Make sure the document does not need to be scaled (and scaling to fit is disabled) (for 4x6 that means 812 x 1218 pixels max)
  - Make sure the document is black and white (no grayscale)
ZPL is a beast.

Some PDFs embed a single image in them, in which case you can do the following;

  pdfimages -all .pdf 
  convert .png -filter point -density 203 -units PixelsPerInch out.png
And then print the generated png.

Re: Writing a printer driver in JavaScript

#14
post #5

As someone who has spent an unfortunate amount of time working on shipping label software for ecommerce companies, my advice is to stay the hell away from ZPL. It's the layout language equivalent of C -- too many low-level footguns. Just send 4x6 PDF's to your thermal printer and be done with it. There are so many more tools, of much better quality, available for composing PDF's than you'll ever find for ZPL or other…

Completely agree. I tried scaling down the PDFs but Ghostscript on the Raspberry Pi is far slower than just scaling the 1200px wide PNG to 800px. I still got very readable barcodes, and a 100% delivery rate on my first batch of orders, even with that downsampling. I could be wrong, but I don't think pixel perfect barcodes are necessary with modern scanners. The only thing going for ZPL is the ability to store the lab…

Did you try using imagemagick to convert to the pdf?

Re: Writing a printer driver in JavaScript

#15
It's amazing how old ZPL is. I wrote a Zebra-140 driver (in C..) in something like 1993.

https://github.com/jhallen/joes-sandbox/tree/master/doc/zebr...

It's a simple macro-based typesetting language that can be used to quickly make many different label images from a database. You uploaded the compiled labels into a handheld computer so that labels could be printed on a production line. One option for the computer was the Psion Organizer II.

https://en.wikipedia.org/wiki/Psion_Organiser

Re: Writing a printer driver in JavaScript

#16
post #9

Similarly, some years ago I prototyped an ESC/POS client (?) for a Bluetooth thermal printer. It was implemented as a Chrome Extension/Chrome App pair, because only Apps were allowed to use Chrome's proprietary Bluetooth API back then. Extension and App communicated via postMessage IIRC. I was shocked how well that hack actually worked. Google then sunset Chrome Apps, and Web Bluetooth never happened.

Minor quibble, I'm actually using a Bluetooth device via Chrome as I type this message, so I'm pretty sure Web Bluetooth did in fact happen.

Re: Writing a printer driver in JavaScript

#17
post #16
post #9

Similarly, some years ago I prototyped an ESC/POS client (?) for a Bluetooth thermal printer. It was implemented as a Chrome Extension/Chrome App pair, because only Apps were allowed to use Chrome's proprietary Bluetooth API back then. Extension and App communicated via postMessage IIRC. I was shocked how well that hack actually worked. Google then sunset Chrome Apps, and Web Bluetooth never happened.

Minor quibble, I'm actually using a Bluetooth device via Chrome as I type this message, so I'm pretty sure Web Bluetooth did in fact happen.

Interesting, I didn't know about Web Bluetooth. Mobile browsers seem to have the most complete implementations [0].

[0] https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetoo...

Re: Writing a printer driver in JavaScript

#18

As someone who has spent an unfortunate amount of time working on shipping label software for ecommerce companies, my advice is to stay the hell away from ZPL. It's the layout language equivalent of C -- too many low-level footguns. Just send 4x6 PDF's to your thermal printer and be done with it. There are so many more tools, of much better quality, available for composing PDF's than you'll ever find for ZPL or other…

Heck, if:

- you can target PDF

- you’re married to a JS stack

- your motivation is (quoting the article)

> When you purchase a shipping label through them, they give you the output in either a PDF, PNG, or ZPL format. ZPL would be ideal, since it's just ASCII text which can easily be modified, or even stored in a database along side each order.

It seems like a much more reasonable intermediate format is SVG or JSX, both of which have mature to-PDF solutions, and both of which have much more well-known manipulation stories. Of course, that doesn’t lead to an absolutely bonkers blog title like this. But for anyone considering a similar setup, there are much more conservative options.

Re: Writing a printer driver in JavaScript

#19
> But I bought this Polono label printer off Amazon for ~$140, which was a steal compared to the Zebra models that start around $500.

Secret: Go to Alibaba and find suppliers that will sell you a Zebra ZP888 for around ~$125/unit. They're a Chinese-market version of the venerable LP2844, a workhorse in the shipping industry for over two decades now, and they're brand new.

Edit: Also forgot: If you use a service like Shippo (https://goshippo.com/), you can get an API that'll dump ZPL shipping labels out. Chain your warehouse system to Shippo for the label, then chain the ZPL out to the script and out to the printer.

Post reply on HN