Skip to content

Usage Guide

Documentation index

Looking for a step-by-step intro for one specific platform (CLI, Docker, HTTP, JavaScript/WASM, Android, Rust)? See the platform tutorials. This page is the compact reference they build on. Vector output covers searchable PDF, multipage PDF and scaled PNG options.

Installation

From Source

cd labelize
cargo install --path . --features serve,vector

From Homebrew (macOS/Linux)

brew tap GOODBOY008/homebrew-labelize
brew install labelize

From GitHub Releases

Download the pre-built binary for your platform from Releases, extract, and place in your PATH.


CLI Tool

Convert a ZPL file to PNG

labelize convert label.zpl
# → label.png (same directory)

Convert a TSPL file to PNG

labelize convert label.tspl          # .tspl → PNG; SIZE sets the canvas

Convert an EPL file to PNG

labelize convert label.epl
# → label.png (auto-detected from extension)

Specify output path

labelize convert label.zpl -o output/my_label.png

Generate PDF instead of PNG

labelize convert label.zpl -t pdf
# → label.pdf

Override input format detection

labelize convert data.txt --format zpl

Custom label dimensions

labelize convert label.zpl --width 100 --height 150 --dpmm 12
Option Default Description
--width declared, then 102 Label width in mm; explicit values override the label
--height declared, then 152 Label height in mm; explicit values override the label
--dpmm 8 Dots per mm (6, 8, 12, or 24)
-f, --format auto Input format: zpl, epl, tspl, cpcl or dpl
-t, --type png Output type: png or pdf
-o, --output auto Output file path

Multi-label files

When a ZPL file contains multiple ^XA…^XZ blocks, each label is output as a separate file with a numeric suffix:

labelize convert multi.zpl
# → multi_1.png, multi_2.png, multi_3.png, …

HTTP Server

Start the server

labelize serve
# Listening on 0.0.0.0:8080

Custom host and port

labelize serve --host 127.0.0.1 --port 3000

Health check

curl http://localhost:8080/health
# {"status":"ok"}

Convert ZPL to PNG via HTTP

curl -X POST http://localhost:8080/convert \
  -H "Content-Type: application/zpl" \
  -d '^XA^FO50,50^A0N,40,40^FDHello World^FS^XZ' \
  -o label.png

Convert EPL to PNG via HTTP

curl -X POST http://localhost:8080/convert \
  -H "Content-Type: application/epl" \
  --data-binary @label.epl \
  -o label.png

Convert to PDF via HTTP

Add ?output=pdf to the URL:

curl -X POST "http://localhost:8080/convert?output=pdf" \
  -H "Content-Type: application/zpl" \
  -d '^XA^FO50,50^A0N,40,40^FDHello World^FS^XZ' \
  -o label.pdf

Custom dimensions via query parameters

curl -X POST "http://localhost:8080/convert?width=100&height=62&dpmm=12" \
  -H "Content-Type: application/zpl" \
  -d '^XA^FO50,50^A0N,40,40^FDHello World^FS^XZ' \
  -o label.png
Parameter Default Description
width declared, then 102 Label width in mm
height declared, then 152 Label height in mm
dpmm 8 Dots per mm
output png Output format: png/pdf

Validate label source via HTTP

Syntax-check without rendering: auto-detects the language (or takes an explicit ?language=zpl|epl|tspl|cpcl|dpl) and reports what failed.

curl -X POST http://localhost:8080/validate \
  -d '^XA^FO50,50^A0N,40,40^FDHello World^FS^XZ'
# {"language":"zpl","ok":true,"labels":1}

curl -X POST http://localhost:8080/validate -d 'N
B10,10,0,9,2,4,80,B,"oops"
P1'
# {"language":"epl","ok":false,"labels":0,"error":"Parse error: EPL B command: unsupported bar code type \"9\" (Code 93)"}
Parameter Default Description
language auto Force zpl/epl/tspl/cpcl/dpl (else detect)
dpmm 8 Dots per mm (feeds ZPL ^MU units)

Format label source via HTTP

Pretty-print the source: one command per line, ^XA blocks indented, CRLF normalized, blank runs collapsed. Binary payloads (^FD data, GW/BITMAP graphics) pass through byte-for-byte, so formatted source renders pixel-identically (verified by sha256 on real corpus labels).

curl -X POST http://localhost:8080/format \
  -d '^XA^CF0,60^FO50,50^FDHello^FS^XZ'
# ^XA
#   ^CF0,60
#   ^FO50,50
#   ^FDHello
# ^FS
# ^XZ
Parameter Default Description
language auto Force zpl/epl/tspl/cpcl/dpl (else detect)

Library Usage

Add to your Cargo.toml:

[dependencies]
labelize = "1.8"

Parse and render a label

One call detects the language, parses, resolves the canvas and encodes — see the Rust tutorial for the full guide (composable parse/render path, canvas control, PDF, validate() / format_source() and error handling):

fn main() {
    let input = b"^XA^FO50,50^A0N,40,40^FDHello^FS^XZ";
    let out = labelize::render_png(input, labelize::RenderOptions::default()).unwrap();
    std::fs::write("output.png", out.bytes).unwrap();
}

Render to PDF

use std::io::Cursor;
use labelize::{detect_language, parse_labels, Renderer, DrawerOptions, encode_pdf};

fn main() {
    let input = b"^XA^FO50,50^A0N,40,40^FDHello^FS^XZ";
    let labels = parse_labels(detect_language(input), input, 8).unwrap();

    let opts = DrawerOptions::default();
    let renderer = Renderer::new();

    // Render to image
    let mut png_buf = Cursor::new(Vec::new());
    renderer.draw_label_as_png(&labels[0], &mut png_buf, opts.clone()).unwrap();

    let img = image::load_from_memory(&png_buf.into_inner()).unwrap().to_rgba8();

    // Encode as PDF
    let mut pdf_buf = Cursor::new(Vec::new());
    encode_pdf(&img, &opts, &mut pdf_buf).unwrap();
    std::fs::write("output.pdf", pdf_buf.into_inner()).unwrap();
}

Language reference

The ZPL command matrix is the canonical command reference. The repository README summarizes the other supported languages. For detailed rendering behavior and reference evidence, use the documentation index.

View source on GitHub