Skip to main content

ZPL how-to

Emulate a Zebra printer for testing

To test code that sends ZPL without a printer, run a stand-in that listens on port 9100 and saves what arrives. It shows you the exact bytes your code sent. It does not show you what a printer would do with them: for a picture, put the saved file in Labelary, and before you go live, print on the real printer.

A stand-in printer in Python

The send code in our guides opens a connection to the printer's port 9100, writes the ZPL and closes the connection. This script takes the printer's place: it accepts the connection, reads until the sender closes it, and saves what it read to a file. It needs only the standard library.

python
import socket
import time

# A stand-in for a printer's raw port, for testing. It prints nothing and
# answers nothing: it saves the bytes of each connection to a file.
with socket.create_server(("127.0.0.1", 9100)) as server:
    print("Listening on 127.0.0.1:9100", flush=True)
    while True:
        conn, _ = server.accept()
        with conn:
            data = bytearray()
            while chunk := conn.recv(65536):
                data += chunk
        name = f"label-{time.time_ns()}.zpl"
        with open(name, "wb") as file:
            file.write(data)
        print(f"Saved {len(data)} bytes to {name}", flush=True)

Save it as fake_printer.py and run it, and leave it running:

bash
python3 fake_printer.py
  • Each connection becomes one file in the folder you ran it from, named by the time it arrived. Stop it with Ctrl+C.
  • It listens on 127.0.0.1, so only programs on the same machine can reach it. Anything that can reach the port can write a file there, so keep it that way unless you need otherwise.
  • It takes one connection at a time. While one sender keeps its connection open, the next one waits: in our test its send still returned in 0.03 s, and its file was saved once the first sender closed.
  • We ran it with Python 3.14 on Linux.

The same in Node.js

javascript
import net from 'node:net';
import { writeFileSync } from 'node:fs';

// A stand-in for a printer's raw port, for testing. It prints nothing and
// answers nothing: it saves the bytes of each connection to a file.
let count = 0;
net
  .createServer((socket) => {
    const chunks = [];
    socket.on('data', (chunk) => chunks.push(chunk));
    socket.on('error', (err) => console.error(err.message));
    socket.on('end', () => {
      const data = Buffer.concat(chunks);
      const name = `label-${Date.now()}-${++count}.zpl`;
      writeFileSync(name, data);
      console.log(`Saved ${data.length} bytes to ${name}`);
    });
  })
  .listen(9100, '127.0.0.1', () => console.log('Listening on 127.0.0.1:9100'));

Save it as fake-printer.mjs, so Node.js reads it as a module, and run it:

bash
node fake-printer.mjs
  • It saves each connection to a file when the sender closes it, as the Python one does. It handles several connections at once, so a sender that holds its connection open does not hold up the others.
  • We ran it with Node.js 22 on Linux.

Or netcat, for one send

bash
nc -l 127.0.0.1 9100 > label.zpl

With OpenBSD netcat, the one we used, this saved one connection to label.zpl and exited when the sender closed it. Other versions of netcat take different options.

Point your send code at it

Use the send code from the Python, Node.js or C# guide unchanged, and give it 127.0.0.1 in place of the printer's address. This page sends two labels in one go. Save them as sent.zpl:

zpl
^XA
^CF0,50
^FO60,60^FDTest bin T-01^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDT01-0001^FS
^XZ
^XA
^CF0,50
^FO60,60^FDTest bin T-02^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDT01-0002^FS
^XZ

Then, with the Python guide's send_zpl:

python
send_zpl("127.0.0.1", open("sent.zpl", encoding="utf-8", newline="").read())

With the Node.js guide's sendZpl, and readFileSync from node:fs:

javascript
await sendZpl('127.0.0.1', readFileSync('sent.zpl', 'utf8'));

With the C# guide's SendAsync:

csharp
await ZebraPrinter.SendAsync("127.0.0.1", zpl);

The stand-in says what it saved. Here that was the sample with no line break after the last ^XZ:

text
Saved 171 bytes to label-1795768085169050276.zpl

Compare it with what you meant to send. cmp prints nothing when two files are the same:

bash
cmp sent.zpl label-1795768085169050276.zpl && echo same
  • On 2026-11-27, the Python and Node.js send code each sent this sample, their own guide's hello label, and 684,000 bytes to both stand-ins, and every file matched what was sent. We did not run the C# code against them.
  • Both labels arrived in one file, because the stand-in saves a connection, not a label. It does not split the ^XA to ^XZ blocks apart.
  • This tests the port 9100 route only. The Windows routes in the send guides, the spooler and a shared printer, need a printer installed in Windows, and these stand-ins are not one.

See what it caught

The stand-in saves bytes and draws nothing. To see the labels, send the saved file to Labelary, as the preview guide explains:

bash
curl --silent --data-binary @label-1795768085169050276.zpl --header "X-Linter: On" --dump-header - --output label.png https://api.labelary.com/v1/printers/8dpmm/labels/4x2/0/
  • For this capture, Labelary's X-Total-Count header said 2, one for each label, and the linter listed no warnings. Change the last 0 to 1 for the second label. Asked for a third, it answered ERROR: Requested 3rd label but ZPL only generated 2 labels.
  • The first label's ink covered x 60 to 347, y 59 to 259, and both barcodes decoded, as T01-0001 and T01-0002.
  • Everything you send goes to Labelary, so test with sample data, not real names or case numbers. The preview guide also covers what Labelary's drawing cannot show you.

What a stand-in does not do

  • Read the ZPL. It saves any bytes, ZPL or not, and never says one is wrong. It knows nothing of density, label stock or what a printer has stored, so it cannot show the problems in the 300 dpi or label size guides.
  • Answer. It never writes back. A client that sent ~HS and waited for the printer's status got nothing and gave up after its own 3 s timeout, and the stand-in saved the three bytes ~HS as a file. To test code that reads the status, you would have to add a reply in the format Zebra's ~HS reference gives. We have not.
  • Fail like a printer. It has no paper to run out of, no head to leave open and no ribbon. While it runs, every send succeeds. Stop it to see a refused connection: the Python send code then raised ConnectionRefusedError: [Errno 111] Connection refused and the Node.js code connect ECONNREFUSED 127.0.0.1:9100.
  • Keep settings between labels. A printer keeps some settings from one label to the next, as the several labels guide covers. The stand-in only stores what it was sent.

Emulator apps

Some apps listen on a port the same way and draw each label as it arrives, so you see a picture without a second step. Both of these say they draw through Labelary's service, so the same care with real data applies. We read their pages on 2026-11-27 and have not run either.

  • Zpl Printer, a Chrome App by Simon Binkert, from the Chrome Web Store. Its listing says it is based on Labelary's web service, that you set the print density, the label size and the TCP server it listens on, and that it can save labels as PNG or PDF files. Version 1.6, updated 4 November 2016.
    • Its manifest, shown in the listing, is a Chrome App's, and gives it access to http://api.labelary.com/*: plain http, not https. It also lets the app listen on *:*, any address and any port.
    • Google's Chrome Apps page says the platform was deprecated in 2020, that Chrome Apps in Kiosk Mode for Enterprise and Education customers are not supported after April 2027, and that the rest in their managed environments reach end of life in October 2028. We have not tried whether current Chrome runs it.
  • Virtual ZPL Printer, an open-source desktop app on GitHub. Its README calls it an Ethernet based virtual Zebra label printer and says it uses Labelary. It lists turning on Labelary's linter and viewing its warnings, loading your own TrueType fonts, and find-and-replace filters on the ZPL it receives. Version 3.5.1, installed from an MSI, needs .NET 10.

A zeepler label, byte for byte

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.

json
1{
2 "config": {
3 "size": "4x2"
4 },
5 "data": {
6 "item": "Écrou M8",
7 "code": "EC-M8-Z"
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": 100
21 }
22 ]
23}

And the ZPL that comes back, ready to send to the printer:

zpl
^XA^MCY^XZ
    ^XA
    ^SZ2
    ^MMT
    ^MNY
    ^LL406
    ^PW812
    ^LH0,0
^CI28
^CF0,50^FO60,60^FDÉcrou M8^FS
^BY2,2,59^FO60,140^BCN,100,N,N,N,A^FDEC-M8-Z^FS
^CI0
^XZ

zeepler returns the ZPL and sends it nowhere: your code sends it to the printer, so the stand-in tests that step the same way. The value here has an accented letter.

  • We sent this response to the Python stand-in with the Python guide's send_zpl, and again with the Node.js guide's sendZpl. Each file it saved matched the response byte for byte: 173 bytes for 172 characters, because É is two bytes in UTF-8.
  • zeepler sets ^CI28 before the elements and switches back to ^CI0 at the end of the label, so the printer reads those two bytes as one letter. The accented characters guide explains why that matters.
  • Drawn in Labelary, the saved file was 1 label, its ink at x 60 to 283, y 49 to 239, and the barcode decoded as EC-M8-Z.
  • 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 200 with the ZPL as plain text. A request the API cannot turn into a label answers 400 with 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.
  • Convert ZPL to PDF or PNG: Labelary's API turns ZPL into a PDF, one label to a page, or a PNG of one label: curl, Python and Node.js, its limits, and what it means to send it your labels.
  • 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.