Browser module for EPSON and STAR thermal printers command line printing.
Installation
npm install browser-thermal-printer --save
Features
importThermalPrinter,{PrinterTypes}from"../browser-thermal-printer";constprinter=newThermalPrinter(PrinterTypes.STAR);printer.print("Hello World");// Append textprinter.println("Hello World");// Append text with new lineprinter.openCashDrawer();// Kick the cash drawerprinter.cut();// Cuts the paper (if printer only supports one mode use this)printer.partialCut();// Cuts the paper leaving a small bridge in middle (if printer supports multiple cut modes)printer.beep();// Sound internal beeper/buzzer (if available)printer.upsideDown(true);// Content is printed upside down (rotated 180 degrees)printer.setCharacterSet("SLOVENIA");// Set character set - default set on initprinter.setPrinterDriver(Object);// Set printer drive - default set on initprinter.bold(true);// Set text boldprinter.invert(true);// Background/text color inversionprinter.underline(true);// Underline text (1 dot thickness)printer.underlineThick(true);// Underline text with thick line (2 dot thickness)printer.drawLine();// Draws a lineprinter.newLine();// Insers break lineprinter.alignCenter();// Align text to centerprinter.alignLeft();// Align text to leftprinter.alignRight();// Align text to rightprinter.setTypeFontA();// Set font type to A (default)printer.setTypeFontB();// Set font type to Bprinter.setTextNormal();// Set text to normalprinter.setTextDoubleHeight();// Set text to double heightprinter.setTextDoubleWidth();// Set text to double widthprinter.setTextQuadArea();// Set text to quad areaprinter.setTextSize(7,7);// Set text height (0-7) and width (0-7)printer.leftRight("Left","Right");// Prints text left and rightprinter.table(["One","Two","Three"]);// Prints table equalyprinter.tableCustom([// Prints table with custom settings (text, align, width, cols, bold){text: "Left",align: "LEFT",width: 0.5},{text: "Center",align: "CENTER",width: 0.25,bold: true},{text: "Right",align: "RIGHT",cols: 8},]);printer.code128("Code128");// Print code128 bar codeprinter.printQR("QR CODE");// Print QR codeawaitprinter.printImage("./assets/olaii-logo-black.png");// Print PNG imageprint.clear();// Clears printText valueprint.getText();// Returns printer buffer string valueprint.getBuffer();// Returns printer buffer - Pass this buffer to printerprint.setBuffer(newBuffer);// Set the printer buffer to a copy of newBufferprint.getWidth();// Get number of characters in one line
How to run examples (Set to EPSON)
node examples/example.ts
2D Barcode Examples
Example settings are the default when not specified.
printer.code128("Code128",{width: "LARGE",// "SMALL", "MEDIUM", "LARGE",height: 80,// 50 < x < 80text: 2,// 1 - No text// 2 - Text on bottom// 3 - No text inline// 4 - Text on bottom inline});printer.printQR("QR Code",{cellSize: 3,// 1 - 8correction: "M",// L(7%), M(15%), Q(25%), H(30%)model: 2,// 1 - Model 1// 2 - Model 2 (standard)// 3 - Micro QR});printer.pdf417("PDF417",{rowHeight: 3,// 2 - 8width: 3,// 2 - 8correction: 1,// Ratio: 1 - 40truncated: false,// booleancolumns: 0,// 1 - 30, 0 auto});printer.maxiCode("MaxiCode",{mode: 4,// 2 - Formatted/structured Carrier Message (US)// 3 - Formatted/structured Carrier Message (International)// 4 - Unformatted data with Standard Error Correction.// 5 - Unformatted data with Enhanced Error Correction.// 6 - For programming hardware devices.});
1D Barcode Example
vardata="GS1-128";// Barcode data (string or buffer)vartype=74;// Barcode type (See Reference)varsettings={// Optional SettingshriPos: 0,// Human readable character 0 - 3 (none, top, bottom, both)hriFont: 0,// Human readable character fontwidth: 3,// Barcode widthheight: 168,// Barcode height};printer.printBarcode(data,type,settings);
vardata="TEST";// Barcode data (string or buffer)vartype=7;// Barcode type (See Reference)varsettings={// Optional Settingscharacters: 1,// Add characters (See Reference)mode: 3,// Barcode mode (See Reference)height: 150,// Barcode height (0≤ height ≤255)};printer.printBarcode(data,type,settings);
Type
#
Type
0
UPC-E
1
UPC-A
2
JAN/EAN8
3
JAN/EAN13
4
Code39
5
ITF
6
CODE128
7
CODE93
8
NW-7
Settings characters
#
Description
1
No added under-bar characters. Executes line feed after printing a bar code
2
Adds under-bar characters. Executes line feed after printing a bar code
3
No added under-bar characters. Does not execute line feed after printing a bar code
4
Adds under-bar characters. Does not execute line feed after printing a bar code