Skip to main content

ZPL how-to

300 dpi printers, and the same ZPL on 203 and 300 dpi

ZPL measures in dots, and a dot is a different size on a 300 dpi printer. The same label prints at two-thirds of the size there. This page shows how to scale a label, what cannot scale exactly, how to write it in millimetres instead, and how to ask a printer which it is.

Dots, millimetres and inches

A "203 dpi" printhead has 8 dots per mm and a "300 dpi" one has 12. Zebra's reference names them by dots per mm (8 and 12 dpmm), and by dpi as 200 and 300.

OneAt 8 dots/mm (203 dpi)At 12 dots/mm (300 dpi)
Dot0.125 mm0.083 mm
Millimetre8 dots12 dots
Inch203.2 dots304.8 dots
4 × 2 inch label (^PW, ^LL)812, 4061219, 609

The label size guide has the other sizes, and the font size guide turns points into dots at both.

Why the same ZPL prints smaller

This 4 × 2 label is laid out in dots for a 203 dpi printer:

zpl
^XA
^FO30,30^GB752,346,4^FS
^CF0,50
^FO60,60^FDBin A-12^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDA12-0042^FS
^FO560,110^BQN,2,4^FDQA,A12-0042^FS
^XZ
  • In Labelary at 8 dpmm the ink covered x 30 to 781, y 30 to 375. At 12 dpmm it covered the same dots, x 30 to 781, y 30 to 375, on an image of 1216 by 608 dots instead of 812 by 406.
  • The same dots are smaller dots. The frame, 752 dots wide, is 94.0 mm at 203 dpi and 62.7 mm at 300: two-thirds of the size, in the top left of the label.
  • Nothing warns you. The printer does what the ZPL says, in its own dots. The reverse happens too: ZPL written for 300 dpi is one and a half times too big at 203, and runs off the label.

Scale it by 1.5

12 ÷ 8 = 1.5. Multiply every position and size in the label by 1.5:

zpl
^XA
^FO45,45^GB1128,519,6^FS
^CF0,75
^FO90,90^FDBin A-12^FS
^BY3^FO90,210^BCN,150,Y,N,N^FDA12-0042^FS
^FO840,165^BQN,2,6^FDQA,A12-0042^FS
^XZ

At 12 dpmm, each part came out the same size as the 203 dpi label at 8:

Width203 dpi label, 8 dpmmScaled, 12 dpmm
The frame752 dots, 94.0 mm1128 dots, 94.0 mm
The text195 dots, 24.4 mm294 dots, 24.5 mm
The barcode246 dots, 30.8 mm369 dots, 30.8 mm
The QR code84 dots, 10.5 mm126 dots, 10.5 mm
  • ^FO, ^GB and the font height (^CF0,50 to ^CF0,75) scale exactly here, because every number was even.
  • ^BY2 became ^BY3: the bars measured 2, 4, 6 dots, then 3, 6, 9. The barcode's height, 100, became 150. Both renders decoded as A12-0042.
  • ^BQ's magnification, the size of one QR module in dots, went from 4 to 6.
  • Set ^PW and ^LL for the printer too, if you send them: 812 by 406 at 203 dpi is 1219 by 609 at 300.

What does not scale exactly

A barcode's bars and a QR code's modules are whole dots. ^BY takes a module width of 1 to 10 dots and ^BQ a magnification of 1 to 100, both whole numbers in Zebra's reference. Times 1.5, an odd number is not whole, so you round it, up or down. This label uses ^BY3 and magnification 5:

zpl
^XA
^BY3^FO40,40^BCN,100,N,N,N^FDA12-0042^FS
^FO40,200^BQN,2,5^FDQA,A12-0042^FS
^XZ
DrawnBarcode widthQR code width
^BY3, ^BQN,2,5, 8 dpmm369 dots, 46.1 mm105 dots, 13.1 mm
^BY4, ^BQN,2,7, 12 dpmm492 dots, 41.0 mm147 dots, 12.3 mm
^BY5, ^BQN,2,8, 12 dpmm615 dots, 51.3 mm168 dots, 14.0 mm
  • Neither is the same size. Rounding down makes the barcode narrower and its bars thinner, which is harder to scan; rounding up makes it wider, so check it still fits the label.
  • The built-in bitmap fonts, A to H, only grow by whole multiples of their size, Zebra's ^A reference says. ^ADN,36,20 (twice font D) scales to ^ADN,54,30 (three times): the ink was 29 dots tall, then 44. But font A at its own size, ^AAN,9,5, has no 1.5 times: Labelary drew ^AAN,14,8 at twice its size, 14 dots of ink against 7. Font 0 scales to any height.
  • A line 3 dots thick is 4 or 5 at 300 dpi: pick even thicknesses if you will scale the label.

^MU: write the label in millimetres

^MU sets the units for the fields after it: D dots, the default, I inches or M millimetres. Each printer then works out its own dots. This is the first label again, in millimetres:

zpl
^XA
^MUm
^FO3.75,3.75^GB94,43.25,0.5^FS
^CF0,6.25
^FO7.5,7.5^FDBin A-12^FS
^BY0.25^FO7.5,17.5^BCN,12.5,Y,N,N^FDA12-0042^FS
^FO70,13.75^BQN,2,0.5^FDQA,A12-0042^FS
^MUd
^XZ
  • At 8 dpmm Labelary drew it dot for dot the same as the 203 dpi label in dots, and at 12 dpmm dot for dot the same as the label scaled by 1.5. One ZPL, the same size on both.
  • In Labelary, millimetres reached more than positions: the ^GB sizes, the font height in ^CF, the module width in ^BY, the barcode's height and the ^BQ magnification were all read as millimetres. ^BY0.25 is 2 dots at 8 dpmm and 3 at 12; magnification 0.5 is 4 and 6.
  • Zebra's reference gives ^BQ magnification as a whole number from 1 to 100, so 0.5 works in Labelary with no warning, but is outside what Zebra documents. Print a test label before relying on it. Left as a whole number in dots, magnification 4 under ^MUm was read as 4 mm a module, and the QR code ran off the label.
  • Bars are still whole dots, so something rounds. ^BY0.375 is 3 dots at 8 dpmm and 4.5 at 12. Labelary drew 3 and 5: it rounded 4.5 up. What a printer does with it we have not checked.
  • ^MU carries over, Zebra says, until another ^MU. In Labelary it carried into the next label too: ^FO5,5^GB10,10,10^FS, after a label that set ^MUm, drew x 40 to 119, y 40 to 119, a box of 10 mm, not 10 dots. That is why the sample ends with ^MUd.

Inches work the same way, but Labelary does not use 203.2 dots to the inch:

zpl
^XA
^MUi
^FO1,1^GB1,.5,.5^FS
^MUd
^XZ
  • At 8 dpmm it drew x 200 to 399, y 200 to 299: 200 dots to the inch. At 12 dpmm, x 300 to 599, y 300 to 449: 300.
  • Zebra's own ^MU example gives the same box three ways, for a 203 dpi printer: ^FO100,100^GB1024,128,128^FS in dots, ^FO12.5,12.5^GB128,16,16^FS in millimetres and ^FO.493,.493^GB5.044,.631,.631^FS in inches, which is 203 dots to the inch. In Labelary the dots and the millimetres drew x 100 to 1123, y 100 to 227, and the inches x 99 to 1107, y 99 to 224: 15 dots short.
  • Millimetres are exact at both, 8 and 12 dots each. Use them rather than inches, and check a printed label.

^MU's conversion from 200 to 300 dpi

^MU has two more values: ^MUa,b,c converts a format made for b dpi (150, 200 or 300) to c dpi (300 or 600), Zebra's reference says, and matching values turn conversion off. Its examples convert 150 to 300, 150 to 600 and 200 to 600. That makes this look like the answer:

zpl
^XA
^MUd,200,300
^FO30,30^GB752,346,4^FS
^CF0,50
^FO60,60^FDBin A-12^FS
^BY2^FO60,140^BCN,100,Y,N,N^FDA12-0042^FS
^FO560,110^BQN,2,4^FDQA,A12-0042^FS
^XZ
  • Labelary did not convert it, at 12 dpmm or at 8. It drew the same dots as without the ^MU, and its linter said: DPI parameters were ignored because the requested combination (200:300) is invalid.
  • The combinations in Zebra's examples did convert, by whole factors. ^MUd,150,300 at 12 dpmm doubled everything: bars of 4, 8, 12 dots. ^MUd,200,600 at 24 dpmm tripled it: bars of 6, 12, 18, and a QR code 252 dots wide against 84.
  • Conversion moved a ^GF image but did not scale it: a 16 by 8 dot image at ^FO40,40, under ^MUd,150,300, drew at x 80 to 95, y 80 to 87, still 16 by 8.
  • Zebra's parameter table allows 200 to 300, its examples never use it, and its comment says a 300 dpi printer can also print at 150. We have not tried it on a printer. If you use it, print a test label on each model first.
  • ^JM does not help either: Zebra's reference says it halves the density, 12 dots/mm to 6 and 8 to 4, and doubles the size of the format. That makes a 300 dpi printer a 150 dpi one, not 203.

Ask the printer which it is

~HI asks a Zebra printer to identify itself. Zebra's reference gives the answer as XXXXXX,V1.0.0,dpm,000KB,X: the model, the firmware version, the dots per mm (6, 8, 12 or 24), the memory and the options. On a network printer, port 9100:

python
import socket


def printer_dpmm(host: str) -> int:
    # ~HI answers model,version,dots per mm,memory,options.
    with socket.create_connection((host, 9100), timeout=5) as s:
        s.sendall(b'~HI')
        reply = s.recv(1024).decode('ascii')
    return int(reply.strip('\x02\x03\r\n ').split(',')[2])


dpmm = printer_dpmm('192.168.1.50')
print(dpmm, 'dots per mm:', {8: '203 dpi', 12: '300 dpi', 24: '600 dpi'}.get(dpmm, 'check the printer'))
  • We ran it against a stand-in that answered in Zebra's documented shape, with 12 and then 8, and it printed 12 dots per mm: 300 dpi and 8 dots per mm: 203 dpi. It has not been run against a printer; read the reply your model sends before you depend on it.
  • Zebra also documents a Set-Get-Do command, ! U1 getvar "head.resolution.in_dpi", which answers the resolution in dots per inch: 200, 300 or 600.
  • By hand, ~WC prints the printer's configuration label. Zebra's page for it lists the sensor type, network ID, ZPL mode and firmware, but not the resolution, so ~HI is the surer way.

With the dots per mm in hand, pick the ZPL for that printer: the dots version made for it, or one label in millimetres for both.

zeepler makes 203 dpi labels only

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 "item": "Bin A-12",
8 "code": "A12-0042"
9 },
10 "templates": [
11 {
12 "type": "Text",
13 "dataPath": "item",
14 "coords": [60, 60],
15 "font": "0,50"
16 },
17 {
18 "type": "BarCode",
19 "dataPath": "code",
20 "coords": [60, 140],
21 "height": 100
22 },
23 {
24 "type": "QRCode",
25 "dataPath": "code",
26 "coords": [560, 110],
27 "magnification": 4
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^FO60,60^FDBin A-12^FS
^BY2,2,59^FO60,140^BCN,100,N,N,N,A^FDA12-0042^FS
^BY2,2,0^FO560,110^BQN,2,4^FDQA,A12-0042^FS
^XZ

zeepler has no 300 dpi option. Every request is laid out in dots for 8 dots/mm, as this one is: the first sample without its frame or the text under the barcode.

  • size 4x2 is ^PW812 and ^LL406, and coordinates must fall inside those 812 by 406 dots. A request with every number times 1.5, such as coords [840, 165], is refused with a 400, so you cannot scale the request for a 300 dpi printer either.
  • At 8 dpmm Labelary drew the response at x 60 to 643, y 59 to 239. At 12 dpmm it drew the same dots, two-thirds of the size, at x 262 to 845, y 59 to 239: it put the 812 dot print width in the middle of a 1216 dot head. Where a real 300 dpi printer puts it we have not checked.
  • resetPrinter does not reset ^MU. After a label that set ^MUm and did not set it back, Labelary drew nothing of zeepler's label, as every position was read in millimetres. If your own labels use ^MU, send ^XA^MUd^XZ before zeepler's: then it drew the same dots as on its own.
  • For a 300 dpi printer, write the label yourself, scaled or in millimetres as above. If you need 300 dpi from zeepler, tell us at the address below.

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.

Before you go live

  • Print one label on each printer model you support, measure it with a ruler, and scan its barcodes: a preview at the right density shows the dots, not what a printer does with ^MU.
  • Text does not wrap. A value longer than the space you left runs off the edge of the label, so set maxLength on any field whose length you do not control.
  • Coordinates are in dots from the top-left corner. A preview shows the layout; then print one label, measure it, and adjust, because a preview cannot show what your printer does with it.
  • 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.
  • 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.
  • Boxes, lines, underline and bold in ZPL (^GB): Draw boxes and lines with ^GB, print white on black with ^FR, underline text with a line, and make text bolder.
  • 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.
  • GS1-128 barcodes in ZPL, with the check digit: Print GS1-128 with ^BC and FNC1, work out the mod 10 check digit of a GTIN or SSCC, separate fields that vary in length, and what the printer adds itself.
  • Comments in ZPL: ^FX: Write a comment with ^FX, why a caret inside one runs as a command, comments outside ^XA and ^XZ, and why // is not a comment.
  • Emulate a Zebra printer for testing: A stand-in printer on port 9100 in a few lines of Python or Node.js, pointing your send code at it, checking what it caught in Labelary, and what a stand-in cannot test.
  • Convert ZPL to PDF or PNG: Labelary's API turns ZPL into a PDF, one label to a page, or a PNG of one label: curl, Python and Node.js, its limits, and what it means to send it your labels.
  • Convert a PDF to ZPL: Draw each page of the PDF as dots at the printer's resolution and send them as ^GF: a Python script, sizing, grey, the ^GF size limit, and why the label prints as a picture.
  • Convert EPL to ZPL: Translate an EPL2 label to ZPL by hand: each common EPL command and its ZPL equivalent, one label translated line by line, what does not carry over, and switching a printer's language.
  • Convert HTML to ZPL: Two ways from an HTML label to ZPL: draw the page in a headless browser and send the dots as ^GF (a Node.js script), or write the label as ZPL fields, with which HTML and CSS ideas carry over and which do not.

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.