@goodboy008/labelize-wasm
v1.9.0
Published
Labelize ZPL/EPL/TSPL label renderer compiled to WebAssembly — render ZPL/EPL/TSPL to PNG/PDF in browsers, Node.js, and bundlers
Maintainers
Readme
@goodboy008/labelize-wasm
The Labelize ZPL/EPL/TSPL label engine compiled to WebAssembly. Parse and render ZPL, EPL, or TSPL/TSC label data to PNG (or PDF) entirely in the browser, Node.js, or your bundler — no server needed.
Usage
Bundlers (webpack 5, Vite with vite-plugin-wasm)
import { lz_render } from "@goodboy008/labelize-wasm";
const zpl = new TextEncoder().encode("^XA^FO50,50^A0N,40,40^FDHELLO WORLD^FS^XZ");
const png = lz_render(zpl, 102.0, 152.0, 8, false, false, false);
// png is a Uint8Array — pass it to an <img> via URL.createObjectURLThe package is the standard wasm-bindgen bundler output: labelize_wasm.js initializes
the engine at module top level and exports lz_render / lz_render_lang / lz_playground_html.
Node.js (≥ 20)
import { lz_render } from "@goodboy008/labelize-wasm/init";
const zpl = Buffer.from("^XA^FO50,50^A0N,40,40^FDHELLO WORLD^FS^XZ", "ascii");
const png = lz_render(zpl, 102.0, 152.0, 8, false, false, false);The /init subpath instantiates the engine from the packaged .wasm directly,
without bundler support or Node flags.
API
lz_render(src, width_mm, height_mm, dpmm, antialias, want_pdf, is_epl) -> Uint8Array
| param | meaning |
|---|---|
| src | raw label bytes (ZPL, or EPL when is_epl = true) |
| width_mm / height_mm | label canvas size in millimetres (defaults: 102 × 152) |
| dpmm | dots per millimetre (default 8) |
| antialias | keep renderer greys instead of thresholding to 1-bit |
| want_pdf | return a PDF instead of PNG |
| is_epl | parse input as EPL instead of ZPL |
lz_render_lang(src, width_mm, height_mm, dpmm, antialias, want_pdf, lang) -> Uint8Array is the
language-explicit variant: lang is "zpl", "epl", or "tspl" (TSPL/TSC labels; the label's own
SIZE in TSPL does not override the width_mm/height_mm you pass — size the canvas like any other
input). Unknown lang values fall back to ZPL.
import { lz_render_lang } from "@goodboy008/labelize-wasm/init";
const tspl = Buffer.from('SIZE 101.6 mm,152.4 mm\nCLS\nTEXT 40,40,"4",0,1,1,"HELLO WORLD"\nPRINT 1', "ascii");
const png = lz_render_lang(tspl, 101.6, 152.4, 8, false, false, "tspl");Errors throw a string prefixed with the failure stage: 1: parse error, 2: rendering error.
lz_validate(src, dpmm, lang) -> string syntax-checks without rendering and never throws —
the JSON report carries the outcome, so SDK callers get the exact parser error instead of a bare
thrown string:
import { lz_validate } from "@goodboy008/labelize-wasm/init";
const report = JSON.parse(lz_validate(src, 8, "")); // "" = auto-detect the language
// { language: "zpl", ok: true, labels: 1 }
// { language: "epl", ok: false, labels: 0, error: "Parse error: EPL X command requires 5 parameters, got 2" }
if (!report.ok) console.error(`[${report.language}] ${report.error}`);lz_format(src, lang) -> Uint8Array pretty-prints the source: one command per line, ^XA
blocks indented, CRLF normalized. Binary payloads (^FD data, GW/BITMAP graphics) pass
through byte-for-byte, so formatted source renders pixel-identically:
import { lz_format } from "@goodboy008/labelize-wasm/init";
const pretty = new TextDecoder().decode(lz_format(src, "")); // "" = auto-detectlz_playground_html() -> string returns the Labelize playground page (identical to the
HTTP server's /).
Release assets
GitHub releases also attach labelize-wasm-wasm32.zip with the raw glue + .wasm files,
for direct use without npm. See wasm/build.sh to rebuild the engine:
cd wasm && ./build.sh # requires Rust wasm32 target + wasm-bindgen-cliLicense
MIT AND BSD-3-Clause
