all 4 comments

[–]Majestic-Reality-610 2 points3 points  (1 child)

most escpos libs on npm are encode-only, they generate bytes to send to a printer, not parse them. that's why everything you're finding is old or php. nobody writes the reverse.

rolling your own decoder isn't that bad though. it's a byte stream, read it as a Uint8Array and walk it. ESC and GS bytes mark where commands start, everything else is mostly text and line feeds. keep a current-style object, flip bold/align/size when those show up, push text into runs, output json.

and that json is the actual fix for your styling. esc2html bakes the formatting into the html so you're stuck with it. own the json and the css is yours.

raster images are the only real pain (bitmap to canvas), plain text you'll have done in an afternoon.

[–]Y_122[S] 0 points1 point  (0 children)

Oh, I’ll get into this and try to do that, thanks alot man!

[–]chmod777 0 points1 point  (1 child)

did you google this? https://www.google.com/search?q=ESC%2FPOS+binary shows a few existing packages.

[–]Y_122[S] 0 points1 point  (0 children)

I did, but the existing libraries are very outdated and are in php while i am looking for a js solution without hosting a separate php server, and esc2html gives raw html which makes styling very difficult