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): thisStores 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.
| Property | Type | Default | Description |
|---|---|---|---|
name | string | Name of the graphic, 1 to 8 characters | |
graphic | Graphic | 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): thisStores a TrueType font (~DU), to use with text({ font: { file: "R:NAME.TTF" } }).
| Property | Type | Default | Description |
|---|---|---|---|
name | string | Name of the font, 1 to 8 characters; it's stored as NAME.TTF | |
data | Uint8Array<ArrayBufferLike> | The .ttf file | |
device? | StorageDevice | "R" | Where to store it: R (DRAM), E (flash), B or A |
Other methods
| Method | Does |
|---|---|
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[]): PrintJobSetup and labels to send together, in order. A part is anything with toZPL(), like a Label or PrinterSetup. See Printing.
| Property | Type | Default | Description |
|---|---|---|---|
minify? | boolean | true | Leave out the line breaks between parts in the output |
| Method | Returns |
|---|---|
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 |
parts | The 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:
| Property | Type | Description |
|---|---|---|
width | number | Width in pixels |
height | number | Height in pixels |
data | ArrayLike<number> | Red, green, blue and alpha for each pixel, row by row |
It returns a ZplImage, ready for graphic() or storeGraphic():
| Property | Type | Description |
|---|---|---|
width | number | Width in dots |
height | number | Height in dots |
totalBytes | number | Size of the graphic data in bytes |
bytesPerRow | number | Bytes in each row, 8 dots to a byte |
data | string | The graphic as hex, compressed when |
| Property | Default | Description |
|---|---|---|
compress | true | Compress the data with Zebra's run-length scheme |
blacknessLimitPercentage | 50 | How dark a pixel must be to print, in percent |