@zplkit/render
Render ZPL to images in Node or the browser.
import { renderZpl, renderPrinted, renderLabels, countLabels, encodePng } from "@zplkit/render";Rendering explains how the renderer draws labels.
renderZpl
renderZpl(zpl: string, options: RenderZplOptions): Promise<string[]>Renders ZPL to one base64-encoded PNG per different label. Copies printed with ^PQ that are all the same are one PNG; serialized ones (^SN, ^SF) are one per copy. It can be passed to <zpl-preview>'s configure({ render }).
| Property | Type | Description |
|---|---|---|
widthMm | number | Label width in millimeters |
heightMm | number | Label height in millimeters |
dpmm | number | Dots per millimeter: 6, 8, 12 or 24 |
fonts? | Record<string, Uint8Array<ArrayBufferLike>> | Fonts already on the printer, by path like "E:ARIAL.TTF". Without a device ("ARIAL.TTF"), a font matches references to any device. |
font0? | Uint8Array<ArrayBufferLike> | A TrueType or OpenType font to draw font 0 with, instead of the open-licensed stand-in, like the printer's own if you have a license |
limit? | number | Render only the first labels, counting each different copy, for previews of many serialized labels |
clock? | Date | The printer's clock, for dates and times in ^FC fields, read in local time. Now if not given. |
grayscale | boolean | Anti-aliased edges instead of the printer's whole dots |
renderPrinted
renderPrinted(zpl: string, options: RenderZplOptions): Promise<PrintedLabel[]>Like renderZpl, with how many times each label prints in a row: { png, copies }. ^XA^FO50,50^A0,40^FDBox^FS^PQ3^XZ is one PNG with copies: 3, and ^PQ5,0,2 with a serial number is three, with copies 2, 2 and 1. It's what <zpl-preview> uses.
countLabels
countLabels(zpl: string): { labels: number; printed: number }How many different labels ZPL renders to, and how many labels it prints, without drawing any. With limit in the options, a preview can draw the first few and say how many more there are.
renderLabels
renderLabels(zpl: string, options: RenderOptions): Raster[]Renders ZPL to one Raster per different label: its width and height in dots, ink, a Float32Array with one value per dot from 0 (blank) to 1 (printed), row by row, and copies, how many times it prints in a row. Use it to process the dots yourself.
Without a limit, ZPL that prints more than 10,000 different labels throws a RangeError.
| Property | Type | Default | Description |
|---|---|---|---|
widthMm | number | Label width in millimeters | |
heightMm | number | Label height in millimeters | |
dpmm | number | Dots per millimeter: 6, 8, 12 or 24 | |
antialias? | boolean | false | Anti-alias edges instead of printing whole dots like a printer |
fonts? | Record<string, Uint8Array<ArrayBufferLike>> | Fonts already on the printer, by path like "E:ARIAL.TTF". Without a device ("ARIAL.TTF"), a font matches references to any device. | |
font0? | Uint8Array<ArrayBufferLike> | A TrueType or OpenType font to draw font 0 with, instead of the open-licensed stand-in, like the printer's own if you have a license | |
limit? | number | Render only the first labels, counting each different copy, for previews of many serialized labels | |
clock? | Date | The printer's clock, for dates and times in ^FC fields, read in local time. Now if not given. |
encodePng
encodePng(raster: Raster): Promise<Uint8Array>Encodes a Raster as a grayscale PNG, returned as a Promise<Uint8Array>.