API

Printer setup and print jobs

PrinterSetup, PrintJob and ImageConverter from @zplkit/core.

PrinterSetup

import { PrinterSetup } from "@zplkit/core";

Builds ZPL that changes the printer or stores things on it, rather than printing a label. Its methods chain, and toZPL() returns the ZPL to send. See Printing.

storeGraphic

setup.storeGraphic(options: StoreGraphicOptions): this

Stores an image (~DG), to print it on labels with storedGraphic(). It stays until it's deleted with deleteGraphic(), or on R: until the printer turns off.

PropertyTypeDefaultDescription
namestring

Name of the graphic, 1 to 8 characters

graphicGraphic

The image, for example from ImageConverter

device?StorageDevice"R"

Where to store it: R (DRAM), E (flash), B or A

storeFont

setup.storeFont(options: StoreFontOptions): this

Stores a TrueType font (~DU), to use with text({ font: { file: "R:NAME.TTF" } }).

PropertyTypeDefaultDescription
namestring

Name of the font, 1 to 8 characters; it's stored as NAME.TTF

dataUint8Array<ArrayBufferLike>

The .ttf file

device?StorageDevice"R"

Where to store it: R (DRAM), E (flash), B or A

Other methods

MethodDoes
setDarkness(darkness)Sets print darkness (~SD), 0 to 30, for every label after. For one label, use its darkness option
setLabelShift(dots)Moves every field left, or right when negative (^LS), -9999 to 9999 dots
setLabelTop(dots)Moves every field down, or up when negative (^LT), -120 to 120 dots
setMirror(mirror)Prints labels as their mirror image (^PM), for clear media printed from the back

Like darkness, the printer keeps shift, top and mirroring until they're set again, so they belong in printer setup rather than in a label. Each is sent in its own format, without fields. | deleteGraphic(name, device?) | Deletes a stored graphic (^ID), from R: unless another device is given |

PrintJob

import { PrintJob } from "@zplkit/core";
new PrintJob(...parts: PrintJobPart[]): PrintJob
new PrintJob(options: PrintJobOptions, ...parts: PrintJobPart[]): PrintJob

Setup and labels to send together, in order. A part is anything with toZPL(), like a Label or PrinterSetup. See Printing.

PropertyTypeDefaultDescription
minify?booleantrue

Leave out the line breaks between parts in the output

MethodReturns
add(...parts)The job, with the parts added to the end
toZPL()The ZPL of every part, in order
lint()Problems the printer won't report in the whole job, as LintDiagnostics
partsThe parts, in order

ImageConverter

import { ImageConverter } from "@zplkit/core/image";

Converts PNG and JPEG images to ZPL graphics. It runs in Node only, so it has its own entry point.

converter.toZPL(image: Uint8Array | Pixels): Promise<ZplImage>

toZPL takes a PNG or JPEG file as a Uint8Array, or pixels:

PropertyTypeDescription
widthnumber

Width in pixels

heightnumber

Height in pixels

dataArrayLike<number>

Red, green, blue and alpha for each pixel, row by row

It returns a ZplImage, ready for graphic() or storeGraphic():

PropertyTypeDescription
widthnumber

Width in dots

heightnumber

Height in dots

totalBytesnumber

Size of the graphic data in bytes

bytesPerRownumber

Bytes in each row, 8 dots to a byte

datastring

The graphic as hex, compressed when compress is on

PropertyDefaultDescription
compresstrueCompress the data with Zebra's run-length scheme
blacknessLimitPercentage50How dark a pixel must be to print, in percent