Skip to main content

ZPL how-to

Comments in ZPL: ^FX

ZPL has one way to write a comment: ^FX. It is not printed, and it ends at the next ^ or ~, which is the one thing to watch.

In plain ZPL

zpl
^XA
^FX Bin label, 4 x 2 at 203 dpi.
Item name, then item code.^FS
^CF0,50
^FX The item name^FS
^FO60,60^FDBin A-12^FS
^FX The item code, Code 128^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDA12-0042^FS
^XZ
  • ^FX is followed by the comment. Zebra's reference says any data after it, up to the next ^ or ~ command, has no effect on the label, and that correct usage follows it with ^FS.
  • The comment is not printed. In Labelary this label drew the same dots as the same label with every ^FX taken out, with no linter warnings.
  • A comment can run over more than one line, as the first one does: it ends at the next caret, not at the end of the line.
  • Without the ^FS after each comment, Labelary drew the same dots too, because the next caret ended it anyway. Zebra's page still asks for the ^FS, so keep it.

A caret ends the comment

Because a comment runs to the next caret, a caret inside one starts a real command:

zpl
^XA
^BY2
^FX Was ^BY3^FS
^FO60,60^BCN,100,Y,N,N^FDA12-0042^FS
^XZ
  • The note was meant to record an old setting. Instead ^BY3 ran: Labelary drew bars of 3, 6, 9 dots, not 2, 4, 6, and the barcode came out wider. Its linter flagged only the ^FS after it: This ZPL command is not necessary.
  • A tilde does the same, Zebra's page says, so avoid both in a comment. Write the command without its caret:
zpl
^XA
^BY2
^FX Was BY3^FS
^FO60,60^BCN,100,Y,N,N^FDA12-0042^FS
^XZ

That drew bars of 2, 4, 6 dots. The same goes for data: a caret in a field starts a command too, which the special characters guide covers.

Outside ^XA and ^XZ

zpl
^FX Aisle A bin labels^FS
^XA
^CF0,50
^FO60,60^FDBin A-12^FS
^XZ
  • Zebra's ^FX page says comments go within a label format, and its ^XA page says a format starts with ^XA and ends with ^XZ. Neither says what a printer does with a ^FX, or plain text, sent between formats. We have not tried it on a printer.
  • Labelary ignored it and drew the same dots as the label alone, one label, with a warning on the ^FS: This ZPL command must be used inside a label (between ^XA and ^XZ). A plain line of text there, Aisle A bin labels, was ignored too: Ignored unrecognized content.
  • Keep comments between ^XA and ^XZ, where Zebra documents them.

There is no other comment syntax

Zebra's reference has no line comment and no block comment: nothing like //, # or /* */. Text that is not inside an ^FX is not a comment. In Labelary it was read as part of the command before it:

zpl
^XA
^CF0,50
// The item name
^FO60,60^FDBin A-12^FS
^XZ
  • Labelary read the // line as part of ^CF's height and warned: Value '50 // The item name' is not a valid number; suffix '// The item name' was ignored. It drew the same dots as without the line, but that is Labelary recovering, not something Zebra documents. Use ^FX.
  • Inside ^FD, a // is just text and prints.

What a comment costs

The bytes you send. The comments in the first label are 115 of its 195 bytes. Zebra's page does not say they cost anything else, and we have not measured print time. If you send many labels over a slow link, keep long notes in your own code instead.

zeepler adds no comments

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": "Bin A-12",
7 "code": "A12-0042"
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
^CF0,50^FO60,60^FDBin A-12^FS
^BY2,2,59^FO60,140^BCN,100,N,N,N,A^FDA12-0042^FS
^XZ

zeepler writes no ^FX: there is no option for one, and the response is only the label. This request is the first label's text and barcode.

  • The elements come back in the order of templates, after ^LH0,0: here the item name is the first line after it and the barcode the second.
  • If you keep the ZPL and want notes in it, add your own ^FX lines. In Labelary, this response with an ^FX line before each element drew the same dots as the response.
  • A value with a caret in it, even ^FX, is sent under ^FH with the caret escaped, so it prints and never starts a comment.

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.
  • 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 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.