@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.
| Property | Type | Default | Description |
|---|---|---|---|
port? | number | 9100 | The printer's raw port |
timeout? | number | 5000 | 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.
| Property | Type | Default | Description |
|---|---|---|---|
chunkSize? | number | 20 | 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| Method | Does |
|---|---|
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
| Property | Type | Description |
|---|---|---|
ready | boolean | True when nothing stops the printer from printing |
paperOut | boolean | Out of labels |
paused | boolean | Paused, for example from the PAUSE button or ^PP |
headOpen | boolean | The printhead is open |
ribbonOut | boolean | Out of ribbon, in thermal transfer mode |
bufferFull | boolean | The receive buffer is full |
underTemperature | boolean | The head is too cold to print well |
overTemperature | boolean | The head is too hot |
corruptRam | boolean | Configuration data was lost |
labelWaiting | boolean | A label is waiting to be taken, in peel-off mode |
thermalTransfer | boolean | Thermal transfer (with ribbon) rather than direct thermal |
printMode | PrintMode | |
labelLength | number | The label length the printer uses, in dots |
formatsInBuffer | number | Formats received but not printed yet |
labelsRemaining | number | Labels left to print in the current batch |
graphicsStored | number | 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:
| Property | Type | Description |
|---|---|---|
write | function | Send bytes to the printer |
read? | function | The next bytes the printer sent, or undefined when nothing arrives
within |
close | function | Close the connection |