ZPL how-to
EAN-13 and Code 93 barcodes in ZPL
Both barcodes print from one command, but both change some data without telling you: EAN-13 replaces your check digit, and Code 93 takes only capitals, digits and a few symbols as typed.
EAN-13: ^BE
^XA
^BY2^FO40,40^BEN,100,Y,N^FD590123412345^FS
^XZ^BEN,100,Y,N: normal orientation, 100 dots tall, the digits printed under the bars, not above.^BY2makes the narrowest bar 2 dots wide, 0.25 mm at 203 dpi. That is under the 0.264 mm GS1 gives as EAN-13's smallest;^BY3, 0.375 mm, is over it. The samples on this page keep^BY2; change it to^BY3for a code that meets GS1's width.- 100 dots is 12.5 mm at 203 dpi. For retail scanning, GS1's bar height grows with bar width: 22.85 mm at 0.330 mm. At
^BY3that is about 26 mm, 208 dots:^BY3,2,59and^BEN,208,Y,N. With its digits it is 235 dots tall, so it needs a 4x2 label, at a y up to 171. It does not fit a 3x1 label. - Send 12 digits. The printer works out the 13th, the check digit, itself: this label scanned as
5901234123457.
What EAN-13 does to your data
- A 13th digit is replaced. Zebra's reference says
^BEtakes exactly 12 digits. Sent as5901234123450, with a wrong check digit, the label scanned as5901234123457: the printer's check digit, not yours, and no error. If your numbers carry their own check digit, check it before printing, or a wrong one goes unnoticed. - Fewer digits are padded. Eleven digits get a 0 in front: the label for
90123412345scanned as0901234123452. - The first digit prints left of
^FO. In Labelary the code at^FO40started 21 dots further left, at x 19, with the first digit in front of the bars. At^FO0that digit and the margin a scanner needs were off the label, and the code did not scan. The digit starts 21 dots left of x at^BY2and 34 at^BY3, so an x of 40 keeps it on the label either way. - Leave room on the right too. At
^BY3the bars are 285 dots wide, and a scanner needs 21 dots of blank label after them. On a 3x1 label, 609 dots wide, the code scanned at^FO310but not at^FO320. Keep x at most 303 on a 3x1 label, 506 on 4x2. With its digits the code is 127 dots tall, so keep y at most 76 on a 3x1 label, 279 on 4x2.
Code 93: ^BA
^XA
^BY2^FO40,40^BAN,100,Y,N,N^FDPART-42^FS
^XZ^BAN,100,Y,N,N: normal, 100 dots tall, text under the bars, and no check digit printed in that text. It scanned asPART-42.- Capital letters, digits, space and
- . $ / + %scan as sent. In Labelary,AZ09-. $/+%scanned exactly.
Characters Code 93 changes
- Lower case becomes upper case. In Labelary,
part-42scanned asPART-42. &,',(and)are not themselves. Zebra's reference uses these four as stand-ins for Code 93's four shift characters, and each one joins with the character after it to make a single character.O'BRIENscanned as O, a control character, then RIEN: the apostrophe and the B became one character.BIN(2)scanned asBIN2. The text under the bars was garbled too.
Every other character: pairs
Code 93 can hold all 128 ASCII characters, written as pairs: a shift stand-in, then a capital letter. Zebra's reference has the full table. The ones you are most likely to need:
)before a capital makes it lower case:P)A)R)T-42scanned asPart-42.(Fis&,(Gis',(Hand(Iare(and).O(GBRIENscanned asO'BRIEN, andBIN(H2(IasBIN(2).- Each pair is two characters of barcode, so the code gets wider: in Labelary, Part-42 written in pairs was 254 dots wide, against 200 for PART-42.
- Code 128 is simpler when your scanner accepts it: it takes lower case and punctuation as typed, and scanned
A&B(2)exactly. Code 128 barcodes in ZPL covers its width and height.
The same barcodes 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 "ean": "590123412345",7 "part": "PART-42"8 },9 "templates": [10 {11 "type": "BarCode",12 "dataPath": "ean",13 "coords": [40, 40],14 "style": "ean13"15 },16 {17 "type": "BarCode",18 "dataPath": "part",19 "coords": [40, 220],20 "style": "code93"21 }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
^BY3,2,59^FO40,40^BEN,100,Y,N^FD590123412345^FS
^BY2,2,59^FO40,220^BAN,100,Y,N,N^FDPART-42^FS
^XZSet a BarCode element's style to "ean13" or "code93". zeepler emits the same commands as above, 100 dots tall unless you set height, with the text under the bars: EAN-13 after ^BY3,2,59, so its bar width meets GS1's minimum, and Code 93 after ^BY2,2,59. Both scanned as they should.
What zeepler checks, and what it does not yet:
- An
ean13value must be 12 or 13 digits, or the request is refused with a400. A 13th digit is not checked: a wrong one is replaced by the printer, as above, so check it yourself. - A
code93value is not checked either, but zeepler writes lower case and punctuation as the pairs above, so the barcode scans as your data: it sendsO'BRIENasO(GBRIEN. If you write the pairs yourself, set"fullAscii": falseand zeepler sends the value unchanged. coordsis checked only to fall inside the label. Give an EAN-13 an x from 40 to 303 and a y up to 76 on a 3x1 label, or an x to 506 and a y to 279 on 4x2, so its first digit, the blank space after its bars and its digits all fit. Those y limits are for the default height.- The bars are 100 dots (12.5 mm) tall by default, shorter than GS1 asks for retail scanning. For a retail code set
"height": 208: zeepler then sends^BEN,208,Y,N, 235 dots tall with its digits, so it needs a 4x2 label, at a y up to 171. It does not fit a 3x1 label: zeepler refuses an EAN-13 height over the label's less its 27 dots of digits, 176 on 3x1 and 379 on 4x2.
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.
- 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.
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.