ZPL how-to
Rotate text and barcodes in ZPL
ZPL fonts and most barcodes take an orientation letter: N normal, R a quarter turn clockwise, I upside down, B a quarter turn the other way, read from the bottom up. QR codes do not turn.
Rotate text: the letter after the font
^XA
^FO100,40^A0R,50,50^FDRack 12^FS
^XZ^A0R,50,50: font 0, turned clockwise, 50 dots tall and wide. The text reads from top to bottom.^FOis the top-left corner of the turned field. In Labelary the text printed at x 112 to 150, y 43 to 196; unturned, at x 103 to 256, y 39 to 77.Bturns it the other way, read from the bottom up, from the same corner:It printed at x 99 to 137, y 42 to 195.zpl^XA ^FO100,40^A0B,50,50^FDRack 12^FS ^XZIprinted upside down, at x 102 to 255, y 52 to 90.^FTgives the start of the baseline instead of the corner. ForBthat is at the bottom, so the text runs up from y 300, with its baseline at x 100:It printed at x 62 to 100, y 143 to 296.zpl^XA ^FT100,300^A0B,50,50^FDRack 12^FS ^XZ
Rotate a barcode
^XA
^BY2^FO100,40^BCR,80,Y,N,N^FDR12-A^FS
^XZ- The letter is
^BC's first value. The bars ran down the label from y 40 to 219, starting at the^FOx. - In Labelary the text line went on the bars' left, outside the
^FOcorner, from x 80. Leave room for it. - QR codes have no orientation letter. Zebra's
^BQreference gives normal only, and says^FWdoes not turn them.
Every field at once: ^FW
^XA
^FWR
^FO100,40^A0,50,50^FDRack 12^FS
^FO300,40^BY2^BCN,80,Y,N,N^FDR12-A^FS
^XZ^FWR sets the orientation for every field after it that does not give its own. The text, ^A0 with no letter, turned. The barcode, ^BCN, stayed as it was, from x 300 to 479.
The whole label
^POI prints the whole label upside down, for labels that come out of the printer the other way round:
^XA
^POI
^FO100,40^A0N,50,50^FDRack 12^FS
^XZIn Labelary, which turned the 812 by 406 dot label about its middle, the text moved to x 555 to 708, y 328 to 366, the bottom right, upside down. Zebra's reference says ^POI inverts the x and y positions and that ^LL, ^LS, ^LT and ^PF change the result, so on a printer where a field lands depends on its print width and label length. Print one label to check. There is no command for a quarter turn of the whole label: give each field a new position and its own letter.
^FW and ^PO stay set
Zebra's reference: both are kept until the printer is switched off or gets another one. In Labelary, a second label after a ^FWR label printed its text turned, and one after a ^POI label printed upside down. If anything sends ^FW or ^PO to your printer, start each label with ^FWN,0 and ^PON. The ,0 matters: ^FW's second value is the field justification, and ^FWN alone keeps the one an earlier ^FW set. Several labels in one ZPL job covers other settings that carry over.
Rotation and 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 "rack": "Rack 12",7 "code": "R12-A"8 },9 "templates": [10 {11 "type": "Text",12 "dataPath": "rack",13 "coords": [40, 40],14 "font": "0,50",15 "orientation": "R"16 },17 {18 "type": "BarCode",19 "dataPath": "code",20 "coords": [120, 40],21 "orientation": "R"22 }23 ]24}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^FO40,40^A0R,50^FDRack 12^FS
^BY2,2,59^FO120,40^BCR,,N,N,N,A^FDR12-A^FS
^XZGive a Text or BarCode element an orientation: N, R, I or B, as above. zeepler sends a turned Text as ^A with the element's font and the letter, so it needs a font, and sends the letter as the barcode command's first value. This request turns both a quarter clockwise. In Labelary it printed at x 52 to 178, y 40 to 219.
coordsis the top-left corner of the turned field, as^FOis above.- Turned
RorB, a barcode'sheightruns across the label, so zeepler allows up to the label's width, less any text line, instead of its height. aligncenterandrightwork only withN.- QR codes take no
orientation: zeepler refuses one with a400.
zeepler's labels set neither ^FW nor ^PO unless you ask. A barcode, or a Text turned R, I or B, gives its own letter, so ^FW does not turn it: sent after ^XA^FWR^XZ, this response printed where it did on its own. A Text with orientation N, or none, sends no ^A, though, so it still takes the letter: with the Text's orientation set to N or left out, it printed turned, down to y 196. ^PO and ^FW's justification carry over too: after ^XA^POI^XZ the response printed upside down, at x 633 to 759, y 186 to 365, and after ^XA^FWN,1^XZ at x 2 to 119, y 40 to 219, each field ending at its x instead of starting there.
Set "resetPrinter": true in the request's config and zeepler starts the label with ^FWN,0^PON^PMN^LRN. Sent after ^XA^FWR^POI^XZ or ^XA^FWN,1^XZ, the response with it printed as it did on its own. The ,0 needs Zebra firmware V60.14.x, V50.14.x or later.
If you build the print job yourself, you can send this before zeepler's labels instead. It prints nothing:
^XA^FWN,0^PON^XZAfter it, the response printed as it did on its own, after either label. ^FWN without the ,0 did not undo ^FWN,1: the response still printed at x 2 to 119, y 40 to 219.
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.
Before you go live
- Text does not wrap. A value longer than the space you left runs off the edge of the label, so set
maxLengthon any field whose length you do not control. - Coordinates are in dots from the top-left corner. Print one label, measure it, and adjust: there is no preview.
- Scan every barcode and QR code on a printed label before relying on it.
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.
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.