Printer API

CUTOS printer device features:

  • Supports multiple systems. Supports both Windows and Linux.
  • Supports network printers.
  • Supports the use of CUPS print manager. For specific printer models, see HP Printers/Universal Printers

Installation

npm install @cutos/devices

Import dependencies

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

DevicePrinter

Constructor, create a printer instance

let devPrinter = new DevicePrinter();

DevicePrinter.init

Printer initialization

devPrinter.init(callback)

callback: callback function

Example:
devPrinter.init((result, error) => {
  if (error) {
    console.log(error)
    return;
  }
  console.log(result)
})
  • Return result example:
"Driver device-printer loaded"

DevicePrinter.readDeviceInfo

Read printer information

devPrinter.readDeviceInfo(callback)

callback: callback function

Example:
devPrinter.readDeviceInfo(data => {
  console.log(data)
})
  • Return result example:
{
  "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

Get printer data

devPrinter.onData(callback)
  • callback: callback function
Example:
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

Print test page

devPrinter.printTestPage(printer);
  • printer: printer name; when this parameter is not passed, the default printer is used for printing.

DevicePrinter.printPdfUrl

Print specified pdf file

devPrinter.printPdfUrl(pdfUrl, printer);

results matching ""

    No results matching ""