Node Thermal Printer
Node.js module for Epson, Star, Tanca, Daruma, and Brother thermal printers command line printing.

Installation
npm install node-thermal-printer
Linux specific
Linux requires build-essentials
sudo apt-get install build-essential
Browser specifics
When using inside a browser, the network interface will not work as browsers do not allow opening TCP sockets.
You still need to instruct the compiler to ignore node dependencies. For webpack, it can be done like this:
new webpack.IgnorePlugin({
resourceRegExp: /^fs$|^net$/,
}),
Features
const { ThermalPrinter, PrinterTypes, CharacterSet, BreakLine } = require('node-thermal-printer');
let printer = new ThermalPrinter({
type: PrinterTypes.STAR,
interface: 'tcp://xxx.xxx.xxx.xxx',
characterSet: CharacterSet.PC852_LATIN2,
removeSpecialCharacters: false,
lineCharacter: "=",
breakLine: BreakLine.WORD,
options:{
timeout: 5000
}
});
let isConnected = await printer.isPrinterConnected();
let execute = await printer.execute();
let raw = await printer.raw(Buffer.from("Hello world"));
printer.print("Hello World");
printer.println("Hello World");
printer.openCashDrawer();
printer.cut();
printer.partialCut();
printer.beep();
printer.upsideDown(true);
printer.setCharacterSet(CharacterSet.PC852_LATIN2);
printer.setPrinterDriver(Object)
printer.bold(true);
printer.invert(true);
printer.underline(true);
printer.underlineThick(true);
printer.drawLine();
printer.newLine();
printer.alignCenter();
printer.alignLeft();
printer.alignRight();
printer.setTypeFontA();
printer.setTypeFontB();
printer.setTextNormal();
printer.setTextDoubleHeight();
printer.setTextDoubleWidth();
printer.setTextQuadArea();
printer.setTextSize(7,7);
printer.leftRight("Left", "Right");
printer.table(["One", "Two", "Three"]);
printer.tableCustom([
{ 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");
printer.printQR("QR CODE");
await printer.printImage('./assets/olaii-logo-black.png');
printer.clear();
printer.getText();
printer.getBuffer();
printer.setBuffer(newBuffer);
printer.getWidth();
How to run examples (Set to EPSON)
Network printer
node examples/example.js tcp://xxx.xxx.xxx.xxx
Printer name via Printer module
node examples/example.js 'printer:My Printer'
Local port or file
node examples/example.js '\\.\COM1'
Interface options
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 |
\\.\COM1 | Print via local port or file |
System Printer Drivers
When using a system printer, you need to provide the driver.
Use electron-printer or printer driver:
const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;
const electron = typeof process !== 'undefined' && process.versions && !!process.versions.electron;
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: 'printer:My Printer',
driver: require(electron ? 'electron-printer' : 'printer')
});
Use a custom printer driver:
const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: 'printer:My Printer',
driver: MyCustomDriver
});
printer.setPrinterDriver(MyCustomDriver)
Network printing example
const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: 'tcp://xxx.xxx.xxx.xxx'
});
printer.alignCenter();
printer.println("Hello world");
await printer.printImage('./assets/olaii-logo-black.png')
printer.cut();
try {
let execute = printer.execute()
console.log("Print done!");
} catch (error) {
console.error("Print failed:", error);
}
2D Barcode Examples
Example settings are the default when not specified.
printer.code128("Code128", {
width: "LARGE",
height: 80,
text: 2
});
printer.printQR("QR Code", {
cellSize: 3,
correction: 'M',
model: 2
});
printer.pdf417("PDF417", {
rowHeight: 3,
width: 3,
correction: 1,
truncated: false,
columns: 0
});
printer.maxiCode("MaxiCode", {
mode: 4,
});
1D Barcode Example
var data = "GS1-128"
var type = 74
var settings = {
hriPos: 0,
hriFont: 0,
width: 3,
height: 168
}
printer.printBarcode(data, type, settings);
Epson Barcode Reference
| 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"
var type = 7
var settings = {
characters: 1,
mode: 3,
height: 150,
}
printer.printBarcode(data, type, settings);
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
| 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
| 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 |
Docs
Tested printers
- Star TSP700
- Rongta RP80US
- Rongta RP326-USE
- EPSON TM-T88V
- EPSON TM-T20X
- EPSON TM-T82IIIL
- Posman BTP-R880NP (Type "epson")
- Brother TD-4550DNWB
- Daruma DR800
Character sets
- PC437_USA
- PC850_MULTILINGUAL
- PC860_PORTUGUESE
- PC863_CANADIAN_FRENCH
- PC865_NORDIC
- PC851_GREEK
- PC857_TURKISH
- PC737_GREEK
- ISO8859_7_GREEK
- WPC1252
- PC866_CYRILLIC2
- PC852_LATIN2
- SLOVENIA
- PC858_EURO
- WPC775_BALTIC_RIM
- PC855_CYRILLIC
- PC861_ICELANDIC
- PC862_HEBREW
- PC864_ARABIC
- PC869_GREEK
- ISO8859_2_LATIN2
- ISO8859_15_LATIN9
- PC1125_UKRANIAN
- WPC1250_LATIN2
- WPC1251_CYRILLIC
- WPC1253_GREEK
- WPC1254_TURKISH
- WPC1255_HEBREW
- WPC1256_ARABIC
- WPC1257_BALTIC_RIM
- WPC1258_VIETNAMESE
- KZ1048_KAZAKHSTAN
CHANGELOG
See CHANGELOG.md