ZPL how-to
Printing ^, ~ and _ in ZPL
A ^ or ~ in your data is read as the start of a ZPL command, even inside a field. The text after it disappears, or worse, runs as a command.
What goes wrong
^XA
^CF0,40
^FO40,40^FD2^10 = 1024^FS
^FO40,120^FD10~20 kg^FS
^XZThis prints 2 and 10, and nothing else. The printer takes ^10 and ~20 as commands it does not know, and the rest of each field goes with them.
When the data comes from people, it can be worse: a value containing ~JA cancels everything waiting to print.
In plain ZPL
^XA
^CF0,40
^FO40,40^FH_^FD2_5E10 = 1024^FS
^FO40,120^FH_^FD10_7E20 kg^FS
^FO40,200^FH_^FDPART_5F0042^FS
^XZ^FH_before^FDsays the field holds hex escapes, each an underscore followed by two hex digits.- Write
^as_5E,~as_7E, and an underscore itself as_5F, since under^FHa bare underscore starts an escape. ^CCand^CTcan change the command characters instead, but they change them for everything that follows. Escaping the field keeps the fix where the problem is.
The same label with zeepler
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 "formula": "2^10 = 1024",7 "range": "10~20 kg",8 "part": "PART_0042"9 },10 "templates": [11 {12 "type": "Text",13 "dataPath": "formula",14 "coords": [40, 40],15 "font": "0,40"16 },17 {18 "type": "Text",19 "dataPath": "range",20 "coords": [40, 120]21 },22 {23 "type": "Text",24 "dataPath": "part",25 "coords": [40, 200]26 }27 ]28}And the ZPL that comes back, ready to send to the printer:
^XA^MCY^XZ
^XA
^SZ2
^MMT
^MNY
^LL406
^PW812
^LH0,0
^CF0,40^FO40,40^FH_^FD2_5E10 = 1024^FS
^FO40,120^FH_^FD10_7E20 kg^FS
^FO40,200^FH_^FDPART_5F0042^FS
^XZSend the values as they are. zeepler escapes ^, ~ and _ under ^FH in any field that has them, so they print and never run as commands. A field without them goes out unchanged.
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.
- 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.
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.