Printer API

CUTOS打印机设备功能:

  • 支持多系统。可同时支持 Windows、Linux。
  • 支持网络打印机。
  • 支持使用 CUPS 打印管理器。查询具体打印机型号,详见 惠普打印机/通用打印机

安装

npm install @cutos/devices

引入依赖

import {DevicePrinter, PrinterCMD} from '@cutos/devices';

DevicePrinter

构造函数, 创建打印机实例

let devPrinter = new DevicePrinter();

DevicePrinter.init

打印机初始化

devPrinter.init(callback)

callback: 回调函数

举例:
devPrinter.init((result, error) => {
  if (error) {
    console.log(error)
    return;
  }
  console.log(result)
})
  • 返回结果示例:
 "Driver device-printer loaded"

DevicePrinter.readDeviceInfo

读取打印机信息

devPrinter.readDeviceInfo(callback)

callback: 回调函数

举例:
devPrinter.readDeviceInfo(data => {
  console.log(data)
})
  • 返回结果示例:
{
  "name": "w80",
  "shareName": "w80",
  "portName": "USB001",
  "driverName": "MSW Printer Driver",
  "printProcessor": "winprint",
  "datatype": "RAW",
  "status": [],
  "statusNumber": 0,
  "attributes": [
    "DO-COMPLETE-FIRST",
    "LOCAL"
  ],
  "priority": 1,
  "defaultPriority": 0,
  "averagePPM": 0
}

DevicePrinter.onData

打印机数据获取

devPrinter.onData(callback)
  • callback:回调函数
举例:
devPrinter.onData(function (data) {
  let resp = data.response;
  if (!resp.status) {
    console.warn('err:', resp.msg);
    return;
  }
  switch (data.cmd) {
    case PrinterCMD.PRINT_TEST: //DevicePrinter.printTestPage(printer);
      break
    case PrinterCMD.PRINT_PDF_URL: //DevicePrinter.printPdfUrl(pdfUrl, printer);
      break
  }
});

DevicePrinter.printTestPage

打印测试页

devPrinter.printTestPage(printer);
  • printer:打印机名称;不传此参数时,使用默认打印机打印。

DevicePrinter.printPdfUrl

打印指定pdf文件

devPrinter.printPdfUrl(pdfUrl, printer);

results matching ""

    No results matching ""