ZPL how-to
Boxes, lines, underline and bold in ZPL (^GB)
ZPL draws boxes and lines with one command, ^GB. It has no underline and no bold: an underline is a ^GB line under the text, and bold text is a wider font or the same field printed twice, a dot or two apart.
Boxes and lines with ^GB
^GBw,h,t draws a box w dots wide and h tall, with a border t dots thick, from the ^FO before it. This sample draws two boxes, a line across and a line down:
^XA
^FO40,40^GB300,150,4^FS
^FO420,40^GB300,150,20^FS
^FO40,240^GB680,0,4^FS
^FO40,280^GB0,100,4^FS
^XZ- The border grows inward. The first box covered x 40 to 339, y 40 to 189, 300 by 150 dots, and each side was 4 dots thick: x 40 to 43 and 336 to 339.
- With
tat 20 the second box took the same space, x 420 to 719, y 40 to 189, with sides 20 dots thick, x 420 to 439 and 700 to 719. - A line is a box with no inside. Zebra's reference says
wandhcannot be less thant, so a height of 0 draws a linetdots thick:^GB680,0,4covered x 40 to 719, y 240 to 243. A width of 0 draws a line down, x 40 to 43, y 280 to 379. - Labelary's linter warns about a height of 1 with a 4 dot border:
Value 1 is less than minimum value 4; used 4 instead. - When
tis as big as the shorter side, the box is solid:^GB300,70,70filled x 40 to 339, y 40 to 109.
Rounded corners and white lines
The full command is ^GBw,h,t,c,r. c is the colour, B for black, the default, or W for white. r rounds the corners, from 0 for square to 8.
^XA
^FO40,40^GB300,150,4,B,3^FS
^XZ- Zebra's reference gives the radius as
r/ 8 of half the shorter side. Here that is 3 / 8 of 75 dots, about 28. - The box covered the same space as the square one, x 40 to 339, y 40 to 189, but its top row ran only x 63 to 316, where the square box's ran x 40 to 339.
- A white line draws over what is already there. Across the solid box,
^FO40,73^GB300,4,4,W^FSleft a gap at y 73 to 76.
White text on black with ^FR
^FR in a field prints that field the reverse of what is under it: white on black, black on white. Draw a solid box, then the text over it:
^XA
^FO40,40^GB300,70,70^FS
^FO50,50^A0N,50,50^FR^FDRack 12^FS
^XZ- The solid box alone had 21,000 black dots. With the text over it, there were 18,042: the text's 2,958 dots printed white.
- Draw the box first. With the text before the box, the label was a plain black box, 21,000 dots.
^LRYdoes the same for every field, and Zebra's reference says it stays on until^LRNor the printer is turned off. Sent after a label of only^XA^LRY^XZ, the sample without^FRstill printed 18,042 black dots, white text. With^LRNadded, 21,000: a black box.
Underline text
A font in ZPL has no underline. Draw a line under the text with ^GB:
^XA
^FO40,40^A0N,50,50^FDRack 12^FS
^FO43,82^GB154,3,3^FS
^XZ- "Rack 12" in font 0, 50 dots tall, covered x 43 to 196, y 39 to 77. The line, 154 by 3 dots from x 43, covered x 43 to 196, y 82 to 84, under the whole word.
- The line does not follow the text. Its length is fixed, so a longer value runs past it and a shorter one leaves it hanging. Underline text whose length you know, and measure it in a preview first.
- Here there are 4 clear rows between the text's lowest dot and the line. Letters such as g and y go lower than "Rack 12" does.
Bold text
^A and ^CF have no bold setting. Three ways to get thicker strokes, measured on a capital I in Labelary, across its middle:
- A wider font 0.
^A0N,50,wsets the width separately from the height of 50. At a width of 25 the stroke was 3 dots, at 50 it was 8, at 80 12 and at 100 14. The letters get wider as well. - The same field twice, 2 dots apart. The second copy, 2 dots to the right, made the stroke 2 dots thicker: the I went from 8 to 10. "Rack 12" ran to x 198 instead of 196, the same height.
- A bigger bitmap font. The bitmap fonts, A to H, grow by whole multiples. Font D at 18 dots tall had a 2 dot stroke, at 36 4 and at 54 6: the strokes grow with the letters, so the text is bigger, not bolder.
^XA
^FO40,40^A0N,50,50^FDRack 12^FS
^FO42,40^A0N,50,50^FDRack 12^FS
^XZZebra's reference says how dark text prints depends on the printhead's density and the media. Print a label to see how bold it looks on paper. The font size guide covers ^A and ^CF.
Bold text in a zeepler label
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 "resetPrinter": true5 },6 "data": {7 "rack": "Rack 12",8 "aisle": "Aisle 4"9 },10 "templates": [11 {12 "type": "Text",13 "dataPath": "rack",14 "coords": [40, 40],15 "font": "0,50"16 },17 {18 "type": "Text",19 "dataPath": "rack",20 "coords": [42, 40],21 "font": "0,50"22 },23 {24 "type": "Text",25 "dataPath": "aisle",26 "coords": [40, 110],27 "font": "0,50"28 }29 ]30}And the ZPL that comes back, ready to send to the printer:
^XA^MCY^XZ
^XA
^SZ2
^FWN,0^PON^PMN^LRN
^MMT
^MNY
^LL406
^PW812
^LH0,0
^CF0,50^FO40,40^FDRack 12^FS
^CF0,50^FO42,40^FDRack 12^FS
^CF0,50^FO40,110^FDAisle 4^FS
^XZzeepler's templates are Text, BarCode and QRCode. There is no box, line, underline or reverse template, so bold here is two Text templates on the same dataPath, 2 dots apart.
- In Labelary the rack printed at x 43 to 198, y 39 to 77, the same as the double-printed sample; the aisle, printed once, at x 41 to 175, y 110 to 147.
"resetPrinter": truestarts the label with^FWN,0^PON^PMN^LRN, so an earlier^LRYcannot turn its text white.- Data cannot add a box: zeepler sends
^in a value as a character. A value of^FO0,0^GB100,100,100^FSprinted as that text, x 42 to 365, y 39 to 65.
To put a box or a line on a zeepler label, add the ^GB to the ZPL you get back, before its last ^XZ. The response starts with a short label of its own, ^XA^MCY^XZ, so change only the last one:
const withBox = zpl.replace(/\^XZ\s*$/, '^FO20,20^GB772,366,4^FS\n^XZ\n');Added to this response, that border covered x 20 to 791, y 20 to 385, around the text, each side 4 dots. Preview the result before you print it.
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.
- 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.
- 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.
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.