node-thermal-printer, 本产品是为了控制爱普生热敏打印机而制作的

分享于 

8分钟阅读

GitHub

  繁體 雙語
This npm package was made to control epson thermal printer
  • 源代码名称:node-thermal-printer
  • 源代码网址:http://www.github.com/Klemen1337/node-thermal-printer
  • node-thermal-printer源代码文档
  • node-thermal-printer源代码下载
  • Git URL:
    git://www.github.com/Klemen1337/node-thermal-printer.git
    Git Clone代码到本地:
    git clone http://www.github.com/Klemen1337/node-thermal-printer
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/Klemen1337/node-thermal-printer
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    node-thermal-printer

    用于EPSON和STAR热敏打印机 命令行 打印的Node.js 模块。

    Join the chat at https://gitter.im/Klemen1337/node-thermal-printer

    安装

    $ npm install node-thermal-printer
    特定的Linux

    Linux需要构建要点

    sudo apt-get install build-essential

    特性

    printer.init({
     type:'star', // Printer type: 'star' or 'epson' interface:'/dev/usb/lp0', // Printer interface characterSet:'SLOVENIA', // Printer character set removeSpecialCharacters:false, // Removes special characters - default: false replaceSpecialCharacters:true, // Replaces special characters listed in config files - default: true extraSpecialCharacters:{'£':163} // Adds additional special characters to those listed in the config files});printer.isPrinterConnected( function(isConnected){ } ) // Check if printer is connected, callback passes bool of statusprinter.execute( function(err){ } ); // Executes all the commands. Optional callback returns null if no error, else error messageprinter.raw(newBuffer("Hello world"), function(err){ } ); // Print instantly. Optional callback returns null if no error, else error messageprinter.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.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.leftRight("Left", "Right"); // Prints text left and rightprinter.table(["One", "Two", "Three"]); // Prints table equalyprinter.tableCustom([ // Prints table with custom settings (text, align, width, bold) { text:"Left", align:"LEFT", width:0.5 },
     { text:"Center", align:"CENTER", width:0.25, bold:true },
     { text:"Right", align:"RIGHT", width:0.25 }
    ]);printer.code128("Code128"); // Print code128 bar codeprinter.printQR("https://github.com/Klemen1337/node-thermal-printer"); // Print QR codeprinter.printImage('./assets/olaii-logo-black.png', function(done){ }); // Print PNG image (uses callback)print.clear(); // Clears printText valueprint.getText(); // Returns printer buffer string valueprint.getBuffer(); // Returns printer bufferprint.getWidth(); // Get number of characters in one line

    Interace选项

    示例

    var printer =require("node-thermal-printer");printer.init({
     type:'epson',
     interface:'/dev/usb/lp0'});printer.alignCenter();printer.println("Hello world");printer.printImageBuffer(/* PNG image buffer */, function(done){})printer.printImage('./assets/olaii-logo-black.png', function(done){
     printer.cut();
     printer.execute(function(err){
     if (err) {
     console.error("Print failed", err);
     } else {
     console.log("Print done");
     }
     });
    });

    2D 条码示例

    未指定时,示例设置为默认值。

    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 条码示例

    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);

    爱普生条码参考

    # 类型数据的可能字符长度
    65upc a0 - 911,12
    66upc e0 - 96 - 8,11,
    67JAN130 - 912,13
    68JAN80 - 97,8
    69Code390 - 9,- Z,SP,$, %, *, +,-,/1 - 255
    70ITF ( 共 2个 5 )0 - 92 - 254 ( 偶数)
    71CODABAR ( NW-7 ),/,:2 - 255
    72CODE93- 7跳频1 - 255
    73CODE128- 7跳频2 - 255
    74GS1-128NUL - SP ( 7Fh )2 - 255
    75GS1 DataBar全方位0 - 913
    76GS1 DataBar截断0 - 913
    77GS1 DataBar有限0 - 913
    78GS1 DataBar扩展0 - 9,A - D,- D,SP,"。%, $,',(,),*, +,-,。 <,:,,=,>,{,2 - 255

    使用技巧

    characterSet 可以使用 "raw" 配置,因此根本不需要进行任何替换。

    文档

    测试的打印机:

    • 星形 TSP700
    • Rongta RP80US
    • 爱普生 TM-T88V
    • Posman BTP-R880NP ( 类型"爱普生"

    控制  PAC  PACK  THIS  print  printer  
    相关文章