node-escpos / driver

🖨️ ESC/POS Printer driver for Node.js.
Other
288 stars 27 forks source link

[RFC] Printing by HTML+CSS. #31

Open dohooo opened 1 year ago

dohooo commented 1 year ago

The different printers have a lot of other instruction sets. But most printer has implemented the BMP instruction. So it will be more accessible and customized if we modify the printing content by HTML+CSS.

image
sksar commented 1 year ago

@dohooo This is a good use case, as the content can be built in HTML + CSS. But my take on this is that a raster version of the same content, is not a good direction, and many beginners will make the mistake of doing simple things in HTML + CSS.

What would rather be better is some sort of XML parsing, instead of an imperative approach, we do a declarative approach. So in that world, maybe, we can translate something like this:

printer
        .font('a')
        .align('ct')
        .barcode('5649D7A0', 'CODE39', {
            width : 2,
            height : 50,
            font: "A",
            position: "BTH"
        })
       .cut()

to something like this

<xml>
  <font>A</font>
  <align>CT</align>
  <barcode type="code39" width="2" height="50" font="A" position="BTH">
       5649D7A0
  </barcode>
  <cut/>
</xml>

and vice versa. I hope it makes sense.

dohooo commented 1 year ago

Okay, You're right. It'll not be easy in this simple scene. But we could replace the basic API with HTML control, Such as.

printer.font("some text..").align('ct')
// inside the API
insert("<span align='center'>some text..</span>")

Finally, we convert the DOM data to the image and output BMP data to the printer. Users can still use the simple method to print something, And we still use HTML+CSS to control the content layout.