Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ingoncalves/escpos-xml
JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.
https://github.com/ingoncalves/escpos-xml
escpos handlebars json momentjs numeraljs printer template xml
Last synced: 4 months ago
JSON representation
JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.
- Host: GitHub
- URL: https://github.com/ingoncalves/escpos-xml
- Owner: ingoncalves
- License: apache-2.0
- Created: 2017-09-18T16:34:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-22T20:46:47.000Z (almost 4 years ago)
- Last Synced: 2024-10-01T00:20:52.590Z (4 months ago)
- Topics: escpos, handlebars, json, momentjs, numeraljs, printer, template, xml
- Language: TypeScript
- Homepage:
- Size: 332 KB
- Stars: 48
- Watchers: 5
- Forks: 20
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ESC/POS XML
JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.
**Features:**
- [x] Text
- [x] Text line
- [x] Feed line
- [x] Bold text
- [x] Underline text
- [x] Font size
- [x] Small mode
- [x] White mode
- [x] Align
- [x] Barcode
- [x] QRcode
- [x] Paper cut node
- [ ] Image
- [x] XML with Handlebars
- [x] Handlebars [Moment](http://momentjs.com) Helper
- [x] Handlebars [Numeral](http://numeraljs.com) Helper## Installation
Using npm:
```
npm install --save escpos-xml
```## Usage
In JavaScript:
### From plain XML
```jsimport { EscPos } from 'escpos-xml';
const xml = `
hello world
`;const buffer = EscPos.getBufferXML(xml);
// send this buffer to a stream (eg.: bluetooth)```
### From XML + Handlebars
```jsimport { EscPos } from 'escpos-xml';
const xml = `
{{foo}}
`;const data = {
foo: 'hello word'
};const buffer = EscPos.getBufferFromTemplate(xml, data);
// send this buffer to a stream (eg.: bluetooth)```
### From Builder
```jsimport { EscPos } from 'escpos-xml';
const buffer = EscPos.getBufferBuilder()
.printTextLine('hello world')
.build();
// send this buffer to a stream (eg.: bluetooth)```
## API
Comming soon...
For a while, this example may help you:```js
import { EscPos } from 'escpos-xml';const xml = `
{{title}}
{{subtitle}}
Date: {{moment date format="DD/MM/YYYY HH:mm:ss"}}
{{numeral price format="$ 0,0.00"}}
{{paddedString}}
{{underline}}
{{description}}
{{#if condictionA}}
True A
{{else if condictionB}}
True B
{{else}}
False
{{/if}}
{{barcode}}
{{qrcode}}
`;const data = {
title: 'Tile',
subtitle: 'Subtitle',
description: 'This is a description',
date: new Date(),
price: 1.99,
paddedString: ' Line padded with 4 spaces',
condictionA: false,
condictionB: true,
barcode: '12345678',
qrcode: 'hello qrcode',
underline: 'underline'
}const buffer = EscPos.getBufferFromTemplate(xml, data);
// send this buffer to a stream (eg.: bluetooth)```