Skip to main content

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:

zpl
^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 t at 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 w and h cannot be less than t, so a height of 0 draws a line t dots thick: ^GB680,0,4 covered 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 t is as big as the shorter side, the box is solid: ^GB300,70,70 filled 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.

zpl
^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^FS left 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:

zpl
^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.
  • ^LRY does the same for every field, and Zebra's reference says it stays on until ^LRN or the printer is turned off. Sent after a label of only ^XA^LRY^XZ, the sample without ^FR still printed 18,042 black dots, white text. With ^LRN added, 21,000: a black box.

Underline text

A font in ZPL has no underline. Draw a line under the text with ^GB:

zpl
^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,w sets 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.
zpl
^XA
^FO40,40^A0N,50,50^FDRack 12^FS
^FO42,40^A0N,50,50^FDRack 12^FS
^XZ

Zebra'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.

json
1{
2 "config": {
3 "size": "4x2",
4 "resetPrinter": true
5 },
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:

zpl
^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
^XZ

zeepler'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": true starts the label with ^FWN,0^PON^PMN^LRN, so an earlier ^LRY cannot 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^FS printed 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:

javascript
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 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

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.