Node Thermal Printer
Node.js module for EPSON and STAR thermal printers command line printing.
Installation
$ npm install node-thermal-printer
Linux specific
Linux requires build-essentials
sudo apt-get install build-essential
Features
const ThermalPrinter = printer;const PrinterTypes = types;const PrinterCharSets = charSets; let printer = type: PrinterTypesSTAR // Printer type: 'star' or 'epson' interface: 'tcp://xxx.xxx.xxx.xxx' // Printer interface characterSet: PrinterCharSetsSTARSLOVENIA // Printer character set, may be string or Buffer removeSpecialCharacters: false // Removes special characters - default: false replaceSpecialCharacters: true // Replaces special characters listed in config files - default: true encoding: 'CP1125' // Converts text to encoding selected, see iconv - default: undefined extraSpecialCharacters: '£':163 // Adds additional special characters to those listed in the config files lineCharacter: "-" // Set character for lines - default: "-" options: // Additional options timeout: 5000 // Connection timeout (ms) [applicable only for network printers] - default: 3000 ; let isConnected = await printer; // Check if printer is connected, return bool of statuslet execute = await printer; // Executes all the commands. Returns success or throws errorlet raw = await printer; // Print instantly. Returns success or throws errorprinter; // Append textprinter; // Append text with new lineprinter; // Kick the cash drawerprinter; // Cuts the paper (if printer only supports one mode use this)printer; // Cuts the paper leaving a small bridge in middle (if printer supports multiple cut modes)printer; // Sound internal beeper/buzzer (if available)printer; // Content is printed upside down (rotated 180 degrees) printer; // Set text boldprinter; // Background/text color inversionprinter; // Underline text (1 dot thickness)printer; // Underline text with thick line (2 dot thickness)printer; // Draws a lineprinter; // Insers break line printer; // Align text to centerprinter; // Align text to leftprinter; // Align text to right printer; // Set font type to A (default)printer; // Set font type to B printer; // Set text to normalprinter; // Set text to double heightprinter; // Set text to double widthprinter; // Set text to quad areaprinter; // Set text height (0-7) and width (0-7) printer; // Prints text left and rightprinter; // Prints table equalyprinter; printer; // Print code128 bar codeprinter; // Print QR codeawait printer; // Print PNG image printclear; // Clears printText valueprint; // Returns printer buffer string valueprint; // Returns printer bufferprint; // Set the printer buffer to a copy of newBufferprint; // Get number of characters in one line
Interace options
Value | Descripton |
---|---|
tcp://192.168.0.99:9100 |
Network printer with port |
printer:auto |
Auto select raw system printer via Printer or Electron printer module |
printer:My Printer Name |
Select system printer by name via Printer or Electron printer module module |
\\.\COM1 |
Print via local port or file |
Example
const ThermalPrinter = printer;const PrinterTypes = types; let printer = type: PrinterTypesEPSON interface: 'tcp://xxx.xxx.xxx.xxx'; printer;printer;await printerprinter; try let execute = printer console; catch error console;
2D Barcode Examples
Example settings are the default when not specified.
printer; printer; printer; printer;
1D Barcode Example
var data = "GS1-128" // Barcode data (string or buffer)var type = 74 // Barcode type (See Reference)var settings = // Optional Settings hriPos: 0 // Human readable character 0 - 3 (none, top, bottom, both) hriFont: 0 // Human readable character font width: 3 // Barcode width height: 168 // Barcode height printer;
Epson Barcode Reference
# | Type | Possible Characters | Length of Data |
---|---|---|---|
65 | UPC-A | 0 - 9 | 11, 12 |
66 | UPC-E | 0 - 9 | 6 – 8, 11, 12 |
67 | JAN13 | 0 - 9 | 12, 13 |
68 | JAN8 | 0 - 9 | 7, 8 |
69 | Code39 | 0 – 9, A – Z, SP, $, %, *, +, -, ., / | 1 – 255 |
70 | ITF (Interleaved 2 of 5) | 0 – 9 | 2 – 254 (even number) |
71 | CODABAR (NW-7) | 0 – 9, A – D, a – d, $, +, −, ., /, : | 2 – 255 |
72 | CODE93 | 00h – 7Fh | 1 – 255 |
73 | CODE128 | 00h – 7Fh | 2 - 255 |
74 | GS1-128 | NUL – SP(7Fh) | 2 – 255 |
75 | GS1 DataBar Omnidirectional | 0 – 9 | 13 |
76 | GS1 DataBar Truncated | 0 – 9 | 13 |
77 | GS1 DataBar Limited | 0 – 9 | 13 |
78 | GS1 DataBar Expanded | 0 – 9, A – D, a – d, SP, !, ", %, $, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, _, { | 2 - 255 |
STAR Barcode Reference
var data = "TEST" // Barcode data (string or buffer)var type = 7 // Barcode type (See Reference)var settings = // Optional Settings characters: 1 // Add characters (See Reference) mode: 3 // Barcode mode (See Reference) height: 150 // Barcode height (0≤ height ≤255) printer;
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 |
Settings mode
# | UPC-E, UPC-A, JAN/EAN8, JAN/EAN13, Code128, Code93 | Code39, NW-7 | ITF |
---|---|---|---|
1 | Minimum module 2 dots | Narrow: Wide = 2:6 dots | Narrow: Wide = 2:5 dots |
2 | Minimum module 3 dots | Narrow: Wide = 3:9 dots | Narrow: Wide = 4:10 dots |
3 | Minimum module 4 dots | Narrow: Wide = 4:12 dots | Narrow: Wide = 6:15 dots |
4 | Narrow: Wide = 2:5 dots | Narrow: Wide = 2:4 dots | |
5 | Narrow: Wide = 3:8 dots | Narrow: Wide = 4:8 dots | |
6 | Narrow: Wide = 4:10 dots | Narrow: Wide = 6:12 dots | |
7 | Narrow: Wide = 2:4 dots | Narrow: Wide = 2:6 dots | |
8 | Narrow: Wide = 3:6 dots | Narrow: Wide = 3:9 dots | |
9 | Narrow: Wide = 4:8 dots | Narrow: Wide = 4:12 dots |
Usage Tips
characterSet
may be configured with "raw"
, so no replacement is done at all.
Docs
- STAR: http://www.starmicronics.com/support/mannualfolder/starline_cm_rev1.15_en.pdf
- EPSON: https://reference.epson-biz.com/modules/ref_escpos/index.php
Tested printers:
- Star TSP700
- Rongta RP80US
- EPSON TM-T88V
- Posman BTP-R880NP (Type "epson")
- Epson TM T20II