0.1.1 • Published 2 years ago
@product-simple/escpos v0.1.1
@product-simple/escpos
BETA
Motivation
Most thermal printers on the market support the ESC/POS command protocol made by EPSON (Reference). There seems to be a lack of options when it comes to using typescript to support this protocol. This library serves one fundamental purpose; provide a typescript builder pattern library for constructing ESC/POS compatible buffers in Node.js.
Getting Started
Start by installing the package with your favorite package manager.
Using npm
npm i @product-simple/escpos
Using yarn
yarn add @product-simple/escpos
Using pnpm
pnpm add @product-simple/escpos
Once installed, simply import the package and start building escpos compatible buffers.
import {
DocumentBuilder,
DocumentBuilderFormatOptions,
DefaultFormatter,
FormatTextAlign,
FormatTextUnderline,
NetworkPrinter,
} from '@product-simple/escpos';
// create the builder with default formatting
const builder = new DocumentBuilder(
new DefaultFormatter({
align: FormatTextAlign.Left,
bold: false,
underline: FormatTextUnderline.None,
}),
);
// build our print document
const buffer = builder
.text('Line 1')
.text('Line 2')
.format({ draw: (b) => b.text('underlined text'), underline: FormatTextUnderline.TwoDot })
.cut()
.build();
// create and connect to the printer
const printer = await NetworkPrinter.create({
port: 9100,
host: '192.168.1.87',
});
await printer.write(buffer);
await printer.close();
Features
- Text
- Text line
- Feed line
- Bold text
- Underline text
- Font size
- Small mode
- White mode
- Align
- Barcode
- QRcode
- Paper cut node
- Image (base64) (png only)