zpl-builder
A Rust library for building ZPL II label strings to send to Zebra thermal printers.
Overview
ZPL (Zebra Programming Language) is a label description language interpreted by Zebra printers. This library lets you build valid ZPL strings in Rust without constructing raw strings by hand.
All field values are validated against the ZPL II specification at construction time. An invalid value returns a
ZplError rather than silently producing a malformed command string.
Installation
[]
= "0.1"
Quick start
use ;
let zpl = new
.set_home_position.unwrap
.add_text.unwrap
.add_graphical_box.unwrap
.add_barcode.unwrap
.build;
// Send `zpl` to your printer over TCP, USB, or serial.
Error handling
Every builder method returns Result<LabelBuilder, ZplError>, so you can chain with ?:
use ;
Supported elements
| Method | ZPL command | Description |
|---|---|---|
add_text |
^A / ^FD |
Text field |
add_barcode |
^BY / ^B* |
Barcode (27 types supported) |
add_graphical_box |
^GB |
Rectangle with optional rounded corners |
add_graphical_circle |
^GC |
Circle |
add_graphical_ellipse |
^GE |
Ellipse |
add_graphical_diagonal_line |
^GD |
Diagonal line |
Supported barcode types
Aztec, Code11, Interleaved, Code39, Code49, PlanetCode, Pdf417, EAN8, UpcE, Code93, CodaBlock,
Code128, UPSMaxiCode, EAN13, MicroPDF417, Industrial, Standard, ANSICodeBar, LogMars, MSI, Plessey,
QrCode, Rss, UpcEanExtension, Tlc39, UpcA, DataMatrix.
Validation ranges
| Parameter | Range |
|---|---|
| x / y position | 0 – 32 000 dots |
| Font size | 10 – 32 000 dots |
| Barcode bar width | 1 – 10 dots |
| Barcode width ratio | 2.0 – 3.0 (step 0.1) |
| Barcode height | 1 – 32 000 dots |
| Line thickness | 1 – 32 000 dots |
| Circle / ellipse dimension | 3 – 4 095 dots |
| Box corner rounding | 0 – 8 |
| Box width / height | ≥ thickness, ≤ 32 000 dots |
| Font name | A–Z or 1–9 (single character) |
License
MIT — see LICENSE.