ESC/POS XML
JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.
Features:
- Text
- Text line
- Feed line
- Bold text
- Underline text
- Font size
- Small mode
- White mode
- Align
- Barcode
- QRcode
- Image
- XML with Handlebars
- Handlebars Moment Helper
- Handlebars Numeral Helper
Installation
Using npm:
npm install --save escpos-xml
Usage
In JavaSript:
From plain XML
; const xml = ` <?xml version="1.0" encoding="UTF-8"?> <document> <text-line>hello world</text-line> </document>`; const buffer = EscPos;// send this buffer to a stream (eg.: bluetooth)
From XML + Handlebars
; const xml = ` <?xml version="1.0" encoding="UTF-8"?> <document> <text-line>{{foo}}</text-line> </document>`; const data = foo: 'hello word'; const buffer = EscPos;// send this buffer to a stream (eg.: bluetooth)
From Builder
; const buffer = EscPos ;// send this buffer to a stream (eg.: bluetooth)
API
Comming soon... For a while, this example may help you:
; const xml = ` <?xml version="1.0" encoding="UTF-8"?> <document> <line-feed /> <align mode="center"> <bold> <text-line size="1:1">{{title}}</text-line> </bold> <line-feed /> <small> <text-line>{{subtitle}}</text-line> </small> </align> <small> <text-line>Date: {{moment date format="DD/MM/YYYY HH:mm:ss"}}</text-line> <text-line size="1:0">{{numeral price format="$ 0,0.00"}}</text-line> </small> <line-feed /> <underline> <text-line>{{underline}}</text-line> </underline> <line-feed /> <align mode="center"> <white-mode> <text-line size="1:1">{{description}}</text-line> </white-mode> <line-feed /> <bold> {{#if condictionA}} <text-line size="1:0">True A</text-line> {{else if condictionB}} <text-line size="1:0">True B</text-line> {{else}} <text-line size="1:0">False</text-line> {{/if}} </bold> </align> <line-feed /> <align mode="center"> <barcode system="CODE_128" width="DOT_250">{{barcode}}</barcode> </align> <line-feed /> <align mode="center"> <qrcode ecl="M">{{qrcode}}</qrcode> </align> </document>`; const data = title: 'Tile' subtitle: 'Subtitle' description: 'This is a description' date: price: 199 condictionA: false condictionB: true barcode: '12345678' qrcode: 'hello qrcode' underline: 'underline' const buffer = EscPos;// send this buffer to a stream (eg.: bluetooth)