Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 1 day ago
JSON representation

JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.

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
```js

import { EscPos } from 'escpos-xml';

const xml = `


hello world

`;

const buffer = EscPos.getBufferXML(xml);
// send this buffer to a stream (eg.: bluetooth)

```

### From XML + Handlebars
```js

import { 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
```js

import { 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)

```