Published:
ZPL places a field at the ^FO position you give
it and prints the text to the right. There is no "center" switch for a
plain text field, which is why centered titles drift left or right when the
text changes. There are two reliable ways around it.
A ^FB field block has a width and a justification. Start the
field at the left edge, make the block as wide as the label, allow one
line, and set justification to C. The printer centers the text
with its own font metrics, so the result is right on the paper whatever the
text is.
^XA
^PW812
^FO0,40^A0N,50^FB812,1,0,C^FDSHIP TO^FS
^XZOpen this label in the ZPL viewer →
^FB812,1,0,C means: 812 dots wide (the full 4-inch label at
203 dpi), at most 1 line, no extra line spacing, centered. To center inside a
box instead of the whole label, start ^FO at the box's left edge
and use the box width. Keep the line count at 1 for titles: text longer
than the block wraps, and extra lines print on top of the last one.
Sometimes a block is not an option: rotated text, a field you position
with ^FT, or a layout tool that needs the width up front. Then
the x position is (label width − text width) / 2, and the only
unknown is the text width in dots. Our
API measures it with the same engine the preview
uses:
curl -s https://labelixa.com/v1/text/measure \
-H "Content-Type: application/json" \
-d '{"text": "SHIP TO", "font": "0", "height": 50, "label_width": 812}'
The answer carries width_dots, center_x (the
^FO x to use) and, when you pass block_width, the
number of lines the text needs. The font is our preview font calibrated to
Zebra font 0, so a printer's ROM font can differ by a few dots; the response
says so. For pixel-exact centering on paper, prefer method 1.
Paste the code into the ZPL viewer and
change the text: a centered block stays centered, a fixed ^FO
does not. If the text overflows instead, see
ZPL text runs off the label.
Start the field at the left edge and wrap it in a ^FB block as wide as the label with C justification, for example ^FO0,40^A0N,50^FB812,1,0,C^FDtext^FS on a 4-inch 203 dpi label. The printer then centers it with its own font metrics.
Yes: x = (label width − text width) / 2. The text width in dots can be measured with POST /v1/text/measure, which also returns center_x. It measures with a preview font calibrated to Zebra font 0, so a printer's ROM font can differ by a few dots.
Two ways to print your own font on a Zebra printer: embed it in every label, or upload it once and call it with ^A@. The difference and the limits.
ZPL dots, millimetres and inchesEvery ZPL coordinate is a dot. Conversion tables for 152/203/300/600 dpi, common label sizes in dots, and what really changes when a 203 dpi file moves to 300.
Why can a label format set media type?A label format can switch the printer to thermal transfer — by design. Why ^MT exists, when it helps, and what disabling it costs your fleet.
How to preview a ZPL file without a printerA ZPL file is just text — the label only exists once something draws it. Four ways to see and test a ZPL label without a printer, including CI.