ZPL how-to
Convert ZPL to PDF or PNG
To turn ZPL into a PDF or a PNG, something has to draw it. The usual way is Labelary's API: send it the ZPL with an Accept: application/pdf header and every label comes back as a page of a PDF, or leave the header out for a PNG of one label. Labelary receives every label you send, so send only labels you are allowed to give a third party.
ZPL to PDF
This page uses two 4 × 2 inch labels. Save them as labels.zpl:
^XA
^CF0,50
^FO60,60^FDSample box B-01^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDB01-0001^FS
^XZ
^XA
^CF0,50
^FO60,60^FDSample box B-02^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDB01-0002^FS
^XZThen send the file to Labelary and ask for a PDF:
curl --silent --data-binary @labels.zpl --header "Accept: application/pdf" --dump-header - --output labels.pdf https://api.labelary.com/v1/printers/8dpmm/labels/4x2/Accept: application/pdfasks for a PDF. Without it, Labelary answers with a PNG.- The URL ends after the size, with no label number, so the PDF holds every label, one to a page. Ours had 2 pages, each 288 by 144 points: 4 × 2 inches at 72 points to the inch. The
X-Total-Countheader said 2. - Add a label number, as in
/4x2/0/, and the PDF holds only that label, counting from 0. Ours then had 1 page. - The PDF held no image of the label: its text was set in fonts embedded in the file. Labelary's API page shows pdftotext reading the text back out of one.
ZPL to PNG
curl --silent --data-binary @labels.zpl --output label.png https://api.labelary.com/v1/printers/8dpmm/labels/4x2/0/- A PNG holds one label, so the URL must say which:
0is the first. Labelary's API page says the label number can be left out only for a PDF. - Ours was 812 by 406 pixels, 8-bit grey: one pixel per dot at 8 dpmm. Its ink covered x 60 to 424, y 59 to 259.
- The preview guide covers the same call, the linter, and what Labelary's drawing cannot show you.
Density, size, rotation and page layout
The URL and a few headers set what Labelary draws. Labelary's API page lists the rest:
- Density:
8dpmmin the URL, for a 203 dpi printer. It takes 6, 8, 12 or 24 dpmm; 12 is 300 dpi. - Size:
4x2, the label's width and height in inches. Its page lists 15 inches as the most. - Rotation: an
X-Rotationheader turns the label clockwise by 0, 90, 180 or 270 degrees.
curl --silent --data-binary @labels.zpl --header "Accept: application/pdf" --header "X-Rotation: 90" --output turned.pdf https://api.labelary.com/v1/printers/8dpmm/labels/4x2/That gave 2 pages of 144 by 288 points. The same header on the PNG call gave a 406 by 812 pixel image.
- Page size: by default each page is the size of the label.
X-Page-Sizesets Letter, Legal, A4, A5 or A6, andX-Page-OrientationPortrait or Landscape. - Several labels to a page:
X-Page-Layouttakes columns x rows. With a page size set, Labelary's page says it draws a light dashed border round each label, whichX-Label-Bordercan change.
curl --silent --data-binary @labels.zpl --header "Accept: application/pdf" --header "X-Page-Size: Letter" --header "X-Page-Layout: 2x5" --output sheet.pdf https://api.labelary.com/v1/printers/8dpmm/labels/4x2/With room for ten, our two labels came back on 1 page of 612 by 792 points, US Letter.
From Python
This uses only the standard library. It reads labels.zpl and writes labels.pdf, with every label, and label.png, with the first:
import urllib.request
LABELARY = "https://api.labelary.com/v1/printers/8dpmm/labels/4x2/"
def convert(zpl: bytes, accept: str, label: str = "") -> bytes:
"""Send ZPL to Labelary and return the PDF or PNG it draws."""
request = urllib.request.Request(
LABELARY + label,
data=zpl,
headers={"Accept": accept, "Content-Type": "application/x-www-form-urlencoded"},
)
with urllib.request.urlopen(request, timeout=30) as response:
return response.read()
with open("labels.zpl", "rb") as file:
zpl = file.read()
# Every label in the ZPL, one to a page.
with open("labels.pdf", "wb") as file:
file.write(convert(zpl, "application/pdf"))
# A PNG holds one label: 0 is the first.
with open("label.png", "wb") as file:
file.write(convert(zpl, "image/png", "0/"))Save it as zpl_to_pdf.py next to labels.zpl and run it:
python3 zpl_to_pdf.py- We ran it with Python 3.14 on Linux. It wrote the same 2 pages and the same PNG as curl.
- A request Labelary refuses raises an error. Asked for a third label, it raised
urllib.error.HTTPError: HTTP Error 404: Not Found. The Node.js version below prints Labelary's reason.
From Node.js
import { readFile, writeFile } from 'node:fs/promises';
const LABELARY = 'https://api.labelary.com/v1/printers/8dpmm/labels/4x2/';
// Send ZPL to Labelary and return the PDF or PNG it draws.
async function convert(zpl, accept, label = '') {
const response = await fetch(LABELARY + label, {
method: 'POST',
headers: { Accept: accept, 'Content-Type': 'application/x-www-form-urlencoded' },
body: zpl,
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
return Buffer.from(await response.arrayBuffer());
}
const zpl = await readFile('labels.zpl');
// Every label in the ZPL, one to a page.
await writeFile('labels.pdf', await convert(zpl, 'application/pdf'));
// A PNG holds one label: 0 is the first.
await writeFile('label.png', await convert(zpl, 'image/png', '0/'));Save it as zpl-to-pdf.mjs, so Node.js reads it as a module, next to labels.zpl and run it:
node zpl-to-pdf.mjs- It uses the fetch built into Node.js. We ran it with Node.js 22 on Linux, and it wrote the same pages and the same PNG as the Python script.
- A refused request throws, with Labelary's reason. Asked for a third label:
Error: 404: ERROR: Requested 3rd label but ZPL only generated 2 labels.
Labelary's limits, and your data
- The free API needs no key. Its page lists 3 requests a second, 5,000 a day, 50 labels a request and a 1 MB body. Over a limit, it answers
429or413. Its FAQ says a label with^PQcounts as its^PQquantity of labels. - Its FAQ says the free API comes with no support, privacy or availability commitments, and its API page lists no zero data retention on the free plan. Paid plans, listed at $90 and $228 a month, add those, and Labelary also licenses its engine to run on your own servers.
- Everything you send goes to Labelary. A shipping label holds a name and an address; a hospital label can hold a patient's. Send only labels you are allowed to give a third party, or use a paid plan or a licensed copy that your agreements cover.
We read Labelary's API page and FAQ on 2026-11-27. Its own Python and Node.js examples save a PDF the same way; ours read the ZPL from a file.
Drawing it on your own machine
To keep labels off someone else's server, draw them yourself. BinaryKits.Zpl is an open-source .NET project (MIT licence). Its README says its Viewer package turns ZPL into an image like Labelary but does it locally, and shows it writing a PNG. Its source has a DrawPdf method too.
- Its README says ZPL font download commands are not supported, and you can map ZPL fonts to fonts installed on the machine.
- Its README also links a hosted demo of the viewer. That runs on their server, so a label sent to it leaves your machine like one sent to Labelary. The package, run in your own code, keeps it local.
- We read its README and source on 2026-11-27, and have not run it. Its drawing is its own, so it may not match Labelary's.
The printer emulator guide lists an app that saves labels it receives as PNG or PDF. It draws through Labelary too.
What the PDF is not
- It is Labelary's drawing of the ZPL, not what a printer printed. A printer's density, its stock and the settings it keeps can change the label, as the preview guide explains.
- A PDF printed on an office printer is not a label from a Zebra printer. Scan any barcode on it before you rely on it.
A zeepler label as a PDF
Send this body to POST https://api.zeepler.com/v1/zeeplify with your API key in the x-api-key header. It is a working request, not an illustration: on every change, our tests run this same file through the API's code and compare the result with the ZPL below.
1{2 "config": {3 "size": "4x2"4 },5 "data": {6 "item": "Sample box B-03",7 "code": "B01-0003"8 },9 "templates": [10 {11 "type": "Text",12 "dataPath": "item",13 "coords": [60, 60],14 "font": "0,50"15 },16 {17 "type": "BarCode",18 "dataPath": "code",19 "coords": [60, 140],20 "height": 10021 }22 ]23}And the ZPL that comes back, ready to send to the printer:
^XA^MCY^XZ
^XA
^SZ2
^MMT
^MNY
^LL406
^PW812
^LH0,0
^CF0,50^FO60,60^FDSample box B-03^FS
^BY2,2,59^FO60,140^BCN,100,N,N,N,A^FDB01-0003^FS
^XZzeepler returns ZPL, as plain text, and nothing else: the API has no PDF or image output. To get a PDF of a zeepler label, save the ZPL that comes back as label.zpl and make the same call:
curl --silent --data-binary @label.zpl --header "Accept: application/pdf" --dump-header - --output label.pdf https://api.labelary.com/v1/printers/8dpmm/labels/4x2/- For this response,
X-Total-Countsaid 1 and the PDF had 1 page of 288 by 144 points. The^XA^MCY^XZat the start drew no page of its own. - zeepler does not send your labels to anyone to draw. This call does: it sends the label to Labelary, so the same care with real data applies.
- We sent the response shown here, not a live API call, which needs a key.
Sending it
- Call the API from your own server or integration engine, not from a web page. An API key in a browser is a key anyone can copy.
- A successful call answers
200with the ZPL as plain text. A request the API cannot turn into a label answers400with every problem listed by field, and is not billed. - Send the ZPL to a Zebra or other ZPL printer at 203 dpi. At 300 dpi the same label prints at two-thirds of the size.
The API reference has every field and status code.
Related guides
- QR code size in ZPL: How ^BQ magnification sets the size of a QR code, and how to work out the size in dots.
- Printing ^, ~ and _ in ZPL: Why a caret or tilde in your data cuts the field short, and how ^FH prints them.
- Font size in ZPL: Setting text height with ^A and ^CF, converting points to dots, and why ^CF carries over.
- Send ZPL to a Zebra printer from C#: Send ZPL from .NET to a network printer on port 9100, or to a USB printer through the Windows spooler, without the driver redrawing it.
- Code 128 barcodes in ZPL: Set a Code 128 barcode's width and height with ^BY and ^BC, work out its width in dots, and pick subsets A, B and C.
- Accented characters in ZPL (^CI28): Print é, ç, ô and € with ^CI28, switch the printer back with ^CI0, and what to do on older firmware.
- Send ZPL to a Zebra printer from Python: Send ZPL from Python to a network printer on port 9100, or to a USB printer through the Windows spooler, without the driver redrawing it.
- Change a barcode to a QR code in ZPL: Swap ^BC for ^BQ, start the field data with QA, so the first characters scan, and reset the ^BY left over from the barcode.
- Send ZPL to a Zebra printer from Node.js: Send ZPL from Node.js to a network printer on port 9100 or to a USB printer through a Windows printer share, and print from a web page through your server.
- Label size and origin in ZPL (^PW, ^LL, ^LH): Set the label size in dots with ^PW and ^LL, move 0,0 with ^LH, and stop the last label's settings moving this one.
- Templates in ZPL: store a format with ^DF, fill it with ^XF: Store a label layout on the printer with ^DF and ^FN, fill it with ^XF, and what prints when a field or the format is missing.
- Several labels in one ZPL job: Send several different labels in one job, stop each one inheriting the last one's font and barcode settings, and number a run with ^SN and ^PQ.
- EAN-13 and Code 93 barcodes in ZPL: Print EAN-13 with ^BE and Code 93 with ^BA, and the data each one changes: a replaced check digit, and characters Code 93 cannot hold.
- Print copies of a ZPL label with ^PQ: Print several copies of one label with ^PQ, why ^PQ after ^XZ prints only one, and each serial number twice with ^SN.
- Center text in ZPL with ^FB: Center text of any length with ^FB, why centered text sits a little left, and text too long for the block.
- Center or right-align a barcode in ZPL: Right-align a barcode with the third value of ^FO, center one by working out its width, and why ^FB does not move it.
- Wrap text and new lines in ZPL: Wrap long text with ^FB, start a new line with \&, and stop ^FB writing over its last line or cutting text off.
- Rotate text and barcodes in ZPL: Turn text and barcodes with N, R, I and B, where ^FO and ^FT put a turned field, ^FW and ^POI, and why both stay set.
- Preview ZPL without a printer: See a label before printing it with Labelary's viewer or API, what zeepler's playground shows, and what no preview can tell you.
- Boxes, lines, underline and bold in ZPL (^GB): Draw boxes and lines with ^GB, print white on black with ^FR, underline text with a line, and make text bolder.
- Logos and images in ZPL (^GF, ~DG, ^XG): Print a logo with ^GF, turn a PNG into hex, keep it under the size limit, and store it once with ~DG to print with ^XG.
- GS1-128 barcodes in ZPL, with the check digit: Print GS1-128 with ^BC and FNC1, work out the mod 10 check digit of a GTIN or SSCC, separate fields that vary in length, and what the printer adds itself.
- 300 dpi printers, and the same ZPL on 203 and 300 dpi: Why a 203 dpi label prints smaller at 300 dpi, scaling it by 1.5 and what does not scale exactly, ^MU in millimetres, and reading the printer's resolution.
- Comments in ZPL: ^FX: Write a comment with ^FX, why a caret inside one runs as a command, comments outside ^XA and ^XZ, and why // is not a comment.
- Emulate a Zebra printer for testing: A stand-in printer on port 9100 in a few lines of Python or Node.js, pointing your send code at it, checking what it caught in Labelary, and what a stand-in cannot test.
- Convert a PDF to ZPL: Draw each page of the PDF as dots at the printer's resolution and send them as ^GF: a Python script, sizing, grey, the ^GF size limit, and why the label prints as a picture.
- Convert EPL to ZPL: Translate an EPL2 label to ZPL by hand: each common EPL command and its ZPL equivalent, one label translated line by line, what does not carry over, and switching a printer's language.
- Convert HTML to ZPL: Two ways from an HTML label to ZPL: draw the page in a headless browser and send the dots as ^GF (a Node.js script), or write the label as ZPL fields, with which HTML and CSS ideas carry over and which do not.
Help with an integration
Email info@zeepler.com. You will get a reply within 2 business days. The support policy covers response times and version changes.