Getting started
Install node-zpl and build your first label.
Install
npm install node-zplBuild a label
A label has a size and a resolution. Zebra printers come in 6, 8, 12 and 24 dots per millimeter (152, 203, 300 and 600 dpi); use the one your printer has.
import { Label, mm } from "node-zpl";
const label = new Label({ width: mm(101.6), height: mm(50.8), dpmm: 8 })
.drawText({
position: { x: mm(5), y: mm(5) },
text: "Harbor Parts Co.",
font: { height: mm(7) },
})
.drawCode128({
position: { x: mm(5), y: mm(20) },
data: "10442-B3",
height: mm(13),
});
const zpl = label.toZPL();
// ^XA^PW813^LL406^LRN^CI28^LH0,0^FO40,40^A0,56^FDHarbor Parts Co.^FS...^XZtoZPL() returns the ZPL text to send to the printer. To see what it looks like first, paste it into the playground or show it with the preview component.
Check it
const problems = label.lint();lint() returns problems the printer wouldn't report, like a box thinner than its line or a field outside the label. See linting.
Next steps
- Write labels as JSX instead of method calls.
- Send the label to a printer.