API

@zplkit/print

Send labels to Zebra printers and read their status.

import { Printer } from "@zplkit/print";
import { connectNetworkPrinter } from "@zplkit/print/network";
import { connectUsbPrinter } from "@zplkit/print/usb";
import { connectBluetoothPrinter } from "@zplkit/print/bluetooth";

Printing shows how to use it. It's experimental: built from Zebra's documentation and tested against stand-ins, not yet against real printers.

connectNetworkPrinter

connectNetworkPrinter(host: string, options?: NetworkOptions): Promise<Printer>

Connects to a network printer by IP address or host name. Node, Bun and Deno only.

PropertyTypeDefaultDescription
port?number9100

The printer's raw port

timeout?number5000

How long to wait for the connection, in milliseconds

connectUsbPrinter

connectUsbPrinter(device?: USBDevice): Promise<Printer>

Connects to a USB printer with WebUSB. Without a device, the browser asks which printer to use, so call it from a click. On Windows the system's printer driver usually claims the printer first.

connectBluetoothPrinter

connectBluetoothPrinter(device?: BluetoothDevice, options?: BluetoothOptions): Promise<Printer>

Connects to a printer over Bluetooth LE with Web Bluetooth, through Zebra's Bluetooth LE Parser Service. Without a device, the browser asks which printer to use. Bluetooth LE is slow, about 80 bytes per second in Zebra's measurements.

PropertyTypeDefaultDescription
chunkSize?number20

Bytes per write. Every connection takes 20; larger chunks are faster when the connection allows them, up to 512.

Printer

new Printer(connection: Connection): Printer
MethodDoes
send(zpl)Sends a Label, PrintJob, anything with toZPL(), or a ZPL string, as UTF-8
status(options?)Asks for the printer's status with ~HS; resolves with a PrinterStatus, or NoReply
close()Closes the connection

PrinterStatus

PropertyTypeDescription
readyboolean

True when nothing stops the printer from printing

paperOutboolean

Out of labels

pausedboolean

Paused, for example from the PAUSE button or ^PP

headOpenboolean

The printhead is open

ribbonOutboolean

Out of ribbon, in thermal transfer mode

bufferFullboolean

The receive buffer is full

underTemperatureboolean

The head is too cold to print well

overTemperatureboolean

The head is too hot

corruptRamboolean

Configuration data was lost

labelWaitingboolean

A label is waiting to be taken, in peel-off mode

thermalTransferboolean

Thermal transfer (with ribbon) rather than direct thermal

printModePrintMode
labelLengthnumber

The label length the printer uses, in dots

formatsInBuffernumber

Formats received but not printed yet

labelsRemainingnumber

Labels left to print in the current batch

graphicsStorednumber

Graphics stored on the printer

NoReply

{ ready: false, noReply: true }: the printer didn't answer in time. Printers don't answer ~HS while they're out of media or ribbon, the head is open, the rewinder is full or the head is too hot, so this usually means one of those.

Connection

Make a Printer for any other connection, like a serial port, from an object with these methods:

PropertyTypeDescription
writefunction

Send bytes to the printer

read?function

The next bytes the printer sent, or undefined when nothing arrives within timeout milliseconds. Leave it out for one-way connections.

closefunction

Close the connection