Render ZPL (Zebra Programming Language) to PNG in the browser! Without Labelary or any third-party service.
npm install zpl-renderer-js> ZPL-Renderer-JS is a wrapper of Zebrash by IngridHQ
bash
npm i zpl-renderer-js
`Usage
The NPM package includes .umd, .esm, and .cjs builds. You can find the raw WASM in the Github Releases.
> In case of using the raw WASM you will need to load src/wasm_exec.js and create a wrapper for the function.> [!WARNING]
> The output of this library (per build) is ~8MB as the wasm is inlined inside so no resource has to be loaded separately. It is higly recommended that you use a bundler and lazy load the library (or the component that uses the lib.)
In case of using the
.umd build defer the load of the resource.> [!NOTE]
> Loading the library in a web worker is also recommended and more so if you are planning on doing multiple renderings in a short time span.
For now, you need to use a WebWorker manually. An example WebWorker can be found in
examples/1-zpl-web-worker.ts and a consumer react component in examples/1-zpl-ww-consumer.tsx$3
`ts
import { ready } from "zpl-renderer-js"
import fs from "node:fs";const { api } = await ready;
const label = await api.zplToBase64Async("^XA^FO50,50^ADN,36,20^FDHello^FS^XZ");
fs.writeFileSync("zpl.png", Buffer.from(label, "base64"));
`$3
`ts
import { ready } from "zpl-renderer-js"
import fs from "node:fs";const { api } = await ready;
const labels = await api.zplToBase64MultipleAsync("...");
for (const label in labels) {
fs.writeFileSync(
zpl-${labels.indexOf(label)}.png, Buffer.from(label, "base64"));
}
`$3
`ts
/**
* Asynchronously render a ZPL label into a PNG image (Base64-encoded string).
*
* @param zpl - The raw ZPL code to render.
* @param widthMm - Label width in millimeters. Defaults to 101.6 mm (~4 inches).
* @param heightMm - Label height in millimeters. Defaults to 203.2 mm (~8 inches).
* @param dpmm - Dots per millimeter (print resolution). Defaults to 8 (~203 DPI).
* @returns A Promise that resolves to a Base64-encoded PNG image string representing the rendered label.
* @throws Will throw an error if the ZPL is invalid or rendering fails.
*/
zplToBase64Async: (
zpl: string,
widthMm?: number,
heightMm?: number,
dpmm?: number
) => Promise; /**
* Asynchronously render multiple ZPL labels into PNG images (Base64-encoded strings).
*
* @param zpl - The raw ZPL code containing multiple labels to render.
* @param widthMm - Label width in millimeters. Defaults to 101.6 mm (~4 inches).
* @param heightMm - Label height in millimeters. Defaults to 203.2 mm (~8 inches).
* @param dpmm - Dots per millimeter (print resolution). Defaults to 8 (~203 DPI).
* @returns A Promise that resolves to an array of Base64-encoded PNG image strings representing the rendered labels.
* @throws Will throw an error if the ZPL is invalid or rendering fails.
*/
zplToBase64MultipleAsync: (
zpl: string,
widthMm?: number,
heightMm?: number,
dpmm?: number
) => Promise;
``
#
Made with 💛 by Fabrizz