ZPL how-to
Print copies of a ZPL label with ^PQ
One command inside the label sets how many to print: ^PQ3 before ^XZ prints three copies of the same label, without sending it three times.
Copies: ^PQ
^XA
^CF0,50
^FO40,40^FDShelf 3^FS
^BY2^FO40,110^BCN,100,Y,N,N^FDS03-12^FS
^PQ3
^XZ- In Labelary this printed 3 labels, each scanning as
S03-12. ^PQcan go anywhere between^XAand^XZ. Moved to straight after^XA, it still printed 3.- Zebra's reference allows from 1 to 99,999,999 copies.
Why ^PQ prints only one copy
The usual cause is ^PQ added to the end of the ZPL, after ^XZ:
^XA
^CF0,50
^FO40,40^FDShelf 3^FS
^BY2^FO40,110^BCN,100,Y,N,N^FDS03-12^FS
^XZ
^PQ3In Labelary this printed 1 label. ^PQ belongs to the label it is in, and after ^XZ it is in none. Put it before ^XZ.
Also seen in Labelary:
- Two
^PQin one label: the last one counts.^PQ5then^PQ2printed 2. ^PQ0printed 1. Zebra's reference starts at 1, so do not rely on 0 to print nothing.- Each label's
^PQis its own. Two labels in one job, each with^PQ2, printed 4: two of the first, then two of the second.^PQdoes not carry into the next label (Several labels in one ZPL job).
Copies of each serial number
With ^SN, ^PQ's first value is the total number of labels. Its third, which Zebra's reference calls "replicates of each serial number", repeats each number. Print a short run on your printer before relying on it: Labelary and the wording of Zebra's reference do not agree on how many copies a value gives.
^XA
^CF0,50
^FO40,40^FDShelf 3^FS
^BY2^FO40,110^BCN,100,Y,N,N^SNS03-01,1,Y^FS
^PQ6,0,2
^XZ- In Labelary this printed 6 labels:
S03-01, S03-01, S03-02, S03-02, S03-03, S03-03. Six in all, so three numbers. - In Labelary, 2 printed each number twice, and 1 printed each number once, the same as leaving it out:
^PQ6,0,1printedS03-01, S03-02, S03-03, S03-04, S03-05, S03-06. Zebra's reference gives 0 as "no replicates" and describes 1 as "one replicate of each serial number", which reads as one extra copy. A printer that follows that wording would print three of each number for^PQ6,0,2. - Several labels in one ZPL job explains
^SN.
Pausing between batches
^PQ has more values for printers with a cutter or an operator, described in Zebra's reference and not checked here, since Labelary does not pause or cut:
- The second,
p, pauses the printer after everyplabels.^PQ50,10prints 50 in batches of 10. The default, 0, never pauses. - The fourth,
o, set toY, prints straight through without pausing, and a cutter still cuts after each batch. - The fifth,
e, is for RFID printers: whether a cutter cuts after a voided RFID label.
Copies 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 "copies": 35 },6 "data": {7 "shelf": "Shelf 3",8 "code": "S03-12"9 },10 "templates": [11 {12 "type": "Text",13 "dataPath": "shelf",14 "coords": [40, 40],15 "font": "0,50"16 },17 {18 "type": "BarCode",19 "dataPath": "code",20 "coords": [40, 110]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
^CF0,50^FO40,40^FDShelf 3^FS
^BY2,2,59^FO40,110^BCN,,N,N,N,A^FDS03-12^FS
^PQ3
^XZSet copies in the request's config. zeepler puts ^PQ just before the label's ^XZ, where it counts. In Labelary the response below printed 3 labels.
copiestakes a whole number from 1 to 99,999,999, Zebra's range. Leave it out for one.- Every copy is the same label. For a different serial number on each, send one label per number.
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.
- 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.
- 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.