node-thermal-printer

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 锺离昂然
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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 = require("../node-thermal-printer").printer;
const PrinterTypes = require("../node-thermal-printer").types;

let printer = new ThermalPrinter({
  type: PrinterTypes.STAR,                                  // Printer type: 'star' or 'epson'
  interface: 'tcp://xxx.xxx.xxx.xxx',                       // Printer interface
  characterSet: 'SLOVENIA',                                 // Printer character set - default: SLOVENIA
  removeSpecialCharacters: false,                           // Removes special characters - default: false
  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.isPrinterConnected();       // Check if printer is connected, return bool of status
let execute = await printer.execute();                      // Executes all the commands. Returns success or throws error
let raw = await printer.raw(Buffer.from("Hello world"));    // Print instantly. Returns success or throws error
printer.print("Hello World");                               // Append text
printer.println("Hello World");                             // Append text with new line
printer.openCashDrawer();                                   // Kick the cash drawer
printer.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 init
printer.setPrinterDriver(Object)                            // Set printer drive - default set on init

printer.bold(true);                                         // Set text bold
printer.invert(true);                                       // Background/text color inversion
printer.underline(true);                                    // Underline text (1 dot thickness)
printer.underlineThick(true);                               // Underline text with thick line (2 dot thickness)
printer.drawLine();                                         // Draws a line
printer.newLine();                                          // Insers break line

printer.alignCenter();                                      // Align text to center
printer.alignLeft();                                        // Align text to left
printer.alignRight();                                       // Align text to right

printer.setTypeFontA();                                     // Set font type to A (default)
printer.setTypeFontB();                                     // Set font type to B

printer.setTextNormal();                                    // Set text to normal
printer.setTextDoubleHeight();                              // Set text to double height
printer.setTextDoubleWidth();                               // Set text to double width
printer.setTextQuadArea();                                  // Set text to quad area
printer.setTextSize(7,7);                                   // Set text height (0-7) and width (0-7)

printer.leftRight("Left", "Right");                         // Prints text left and right
printer.table(["One", "Two", "Three"]);                     // Prints table equaly
printer.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 code
printer.printQR("QR CODE");                                 // Print QR code
await printer.printImage('./assets/olaii-logo-black.png');  // Print PNG image

print.clear();                                              // Clears printText value
print.getText();                                            // Returns printer buffer string value
print.getBuffer();                                          // Returns printer buffer
print.setBuffer(newBuffer);                                 // Set the printer buffer to a copy of newBuffer
print.getWidth();                                           // Get number of characters in one line

How to run examples (Set to EPSON)

Network printer

node examples/example.js tcp://xxx.xxx.xxx.xxx

Pritner name via Printer module

node examples/example.js 'printer:My Printer'

Local port or file

node examples/example.js '\\.\COM1'

Interface 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
\\.\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
});

// you can also set the driver after init:
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.error("Print done!");
} catch (error) {
  console.log("Print failed:", error);
}

2D Barcode Examples

Example settings are the default when not specified.

printer.code128("Code128", {
    width: "LARGE",          // "SMALL", "MEDIUM", "LARGE",
    height: 80,              // 50 < x < 80
    text: 2                  // 1 - No text
                             // 2 - Text on bottom
                             // 3 - No text inline
                             // 4 - Text on bottom inline
});

printer.printQR("QR Code", {
    cellSize: 3,             // 1 - 8
    correction: '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 - 8
    width: 3,                // 2 - 8
    correction: 1,           // Ratio: 1 - 40
    truncated: false,        // boolean
    columns: 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

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.printBarcode(data, type, settings);

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.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

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

Docs

Tested printers:

  • Star TSP700
  • Rongta RP80US
  • Rongta RP326-USE
  • EPSON TM-T88V
  • Posman BTP-R880NP (Type "epson")

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

 相关资料
  • Node是kubernetes集群的工作节点,可以是物理机也可以是虚拟机。 Node的状态 Node包括如下状态信息: Address HostName:可以被kubelet中的--hostname-override参数替代。 ExternalIP:可以被集群外部路由到的IP地址。 InternalIP:集群内部使用的IP,集群外部无法访问。 Condition OutOfDisk:磁盘空间不足时

  • node 负责 peer node 子命令。

  • 这用于确定进程需要运行的节点的值。 由于分布式编程用于在不同节点上运行函数,因此在希望在不同机器上运行程序时,此功能非常有用。 语法 (Syntax) node() 参数 (Parameters) None 返回值 (Return Value) 这将返回本地节点的名称。 如果节点未分发,则返回nonode@nohost 。 例如 (For example) -module(helloworld)

  • The Po.et Node The Po.et Node allows you to timestamp documents in a decentralized manner. It's built on top of the Bitcoin blockchain and IPFS. Index The Po.et Node Index How to Run the Po.et Node De

  • Node-Lua是一款基于Lua实现的脚本和服务器引擎,它支持构建海量Lua服务(Context_Lua)并以多线程方式运行在多核服务器上,采用了任务多路复用的设计方案,有效利用了多核优势。node-lua致力于构建一个快速、简单易用的Lua脚本和服务器开发和运行环境。该引擎参考了Node-Js和Skynet的设计思想,并对其进行了整合和优化。 该引擎当前版本实现了以下特性: 引擎核心层同时支持同

  • 在程序里经常都需要生成一些特定格式的 id ,每种场合的需求都可能有些不一样,虽然写起来代码不复杂,但零零碎碎的东西做多了也挺烦的,于是设计了这个用于 node.js 的万能 ID 生成器。 AnyID 生成的 ID 为字符串(也可以纯数字),信息密度尽可能的高,也就是用最少的位数表示尽量多的信息。 AnyID 设计的首要考虑原则是 API 的直观易用。看看这些例子: 指定长度,随机值填充 21