ZPL Nested Start and End Tags - zpl

Can we use nested start and end tag for ZPL as per below structure?
^XA
...
^XA
...
^XZ
...
^XZ
My use case is if you want to apply some property at document level (for all the pages) you can include that in the upper structure instead of including that in each start and end tag.
I have tried this and its giving me correct output.
please suggest me is this correct way to use?

At some point this will not give you the output you expect. The first ^XZ should be denoting the end of the print job and causing the label to print. The second ^XZ is likely being ignored.
The way you would want to set this up is:
^XA
...properties, print speed darkness, etc
...makes setting changes but does not print a label
^XZ
...
^XA
...label code
^XZ

Related

How to center text in ZPL language?

I have the following code which I print a label with the information of a product. But I have the problem that the product name is not centered. It happens to me that if the name is very long, it goes outside the limits of the label and does not appear. What I want is for the name to start from the center and expand along the label and if it exceeds the limits to continue writing on the next line.
I would appreciate any help
^XA
^CF0,30
^FO150,30^FDNombre del Producto^FS
^CF0,60
^FO200,90^FDPrecio^FS
^FX Third section with bar code.
^BY2,2,50
^FO170,180^BC^FD1234789^FS
^XZ
NOTE: This only works if you are using dots as the unit of measurements (this is the default but specified as ^MUd in the example below). If mm is used (^MUm) the center-thingy does NOT work properly (tested on labelary.com and Zebra S4m).
Use ^FB to define a Field Block. From the manual:
The ^FB command allows you to print text into a defined block type
format. This command formats an ^FD or ^SN string into a block of text
using the origin, font, and rotation specified for the text string.
The ^FB command also contains an automatic word-wrap function.
You could view this example at labelary.com or tryit out yourself:
^XA
^MUd
^LH10,10
^CF0,50
^GB500,500,10^FS
^FO0,50 ^FDNormal^FS
^FO0,150 ^FB500,,,L ^FDLeft^FS
^FO0,250 ^FB500,,,C ^FDCenter^FS
^FO0,350 ^FB500,,,R ^FDRight^FS
^XZ

ZebraDesigner - Saving zpl code does not actually save code as zpl

title might be a bit weirdly formulated, so let me try to explain:
I use ZebraDesigner 3 Essentials in order to make a label. I then "print to file", which leaves me with a .prn containing code. I also tried the answer from this question:
How to get ZPL code from a ZebraDesigner label?
, leaving me with a .zpl file, which has the same content as the .prn file.
That content is similiar to zpl, but it seemingly is not the same. This is the result of a simple label, where "Text" is in the middle of it:
CT~~CD,~CC^~CT~
^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR2,2~SD20^JUS^LRN^CI0^XZ
^XA
^MMT
^PW1046
^LL0267
^LS0
^FO448,96^GFA,00768,00768,00012,:Z64:
eJzl0TEOQiEMBuASho69gb2I4V3rDcRg3sHEm3CEjh2M6PMV0Lg4GBc7fUMD/w8AfzBUq7zZpWF8NfgMnxhlmC+Y8SQPT1dfyBzZCU+bZ0oSbF8w6b7Zpxg3u+Jz0GEWc62ZyzDlYWwu93pP7vur2zniIEi/N0cdGdQywIzHnvPAruzMay9G6X1pUXsHSnjWL/7Yz+YGfRNqLw==:7BBD
^PQ1,0,1,Y^XZ
The second line from the button upwards is the problem, I believe. Around there is where, normally, "Text" would be standing, however, now there's just gibberish.
I absolutly need this to be saved correctly, as I later need to access it via python. Please help me by explaining why this happens, and / or how I can fix this.
You need to use a font that is built into the printer. If you set the font to Zebra 0 you get something like:
CT~~CD,~CC^~CT~
^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR4,4~SD22^JUS^LRN^CI0^XZ
^XA
^MMT
^PW812
^LL1218
^LS0
^FT160,391^A0N,135,134^FH\^FDhello^FS
^PQ1,0,1,Y^XZ

ZPL code sent to printer prints 2 blank labels before printing the actual label

The following ZPL code when sent to a Zebra GX-420D printer with 2"x2" labeld loaded, does 2 very strange things:
Skips the first 2 labels and only prints on the 3rd one
Repeat this (2 blank labels + one with content) one more time, after a short delay.
So in total it uses 6 labels, and the content is only on the 3rd and 6th one.
Here's the code:
^XA
^FX Test for long barcode
^BY1,2,50
^FO20,10^BC^FD>6UIQ-2013P-MR-BU^FS
^XZ
Is there anything in the above code that would cause this phenomenon?
^FS at the end of a commented text is optional.
From ZPL II manual :
The ^FS command denotes the end of the field definition.
Alternatively, ^FS command can also be issued as a single ASCII control code SI (Control-O, hexadecimal 0F).
I eventually figured it out. I was trying to remotely fix this, not having a direct access to the printer and not seeing what it printed and how. But eventually I got access to a printer and then it didn't take long to fix.
It seems that there were some defaults or setting left over from the previous print jobs that cause the problem. I added some resetting of values in front of the printing and after that it properly printed out just one label.
And yes, the ^FS was not needed at the end of the comment with ^FX.
Here is the code that printed out the same thing correctly (there might be some unnecessary commands but this one worked so I left it at that):
^XA~TA000~JSN^MNW^PON^PMN^LH0,000~SD15^XZ
^XA^JUS^XZ
^XA
^MMT
^PW0355
^LL0305
^FX Test for long barcode
^BY1,2,50
^FO20,10^BC^FD>6UIQ-2013P-MR-BU^FS
^XZ

How to print price without specyfing location of every part of the text? (ZPL)

The effect he wants to get is:
The price is normally printed
Near the price I want to print the rest of the price in superscript
At the end I want to place currency in subscript.
The problem is that I don't want to specify the location of every part of text.
^XA
^PW480
^FS
^JMA
^MMT
^LS0
^MTD
^CI28
^FO40,11
^FWN
^CF0,16.2,20.7
^FD2144
^FS
^CI28
^FO80,10
^FWN
^CF0,8,8
^FD00
^FS
^CI28
^FO100,10
^FWN^CF0,16.2,17.25
^FDEUR
^FS
^XZ
So the question is that possible to print text after text specifying location only once? Without specifying location to every part of the text?
Use ^FT instead of ^FO, and only specify the X coordinate for the first ^FT.
By default, ^FT resumes at the point where the previous formatting operation finished, and you can provide a manual override to the X and Y components separately, so you would only provide the Y override for the subsequent ^FTs and let it calculate the X automatically:
^FT40,11^A0,16.2,20.7^FD2144^FS
^FT,6^A0,8,8^FD00^FS
^FT,11^A0,16.2,17.25^FDEUR^FS
Note that you will need to adjust the Y coordinate down, because ^FO lines up with the top of the text line (letters hanging from it) and ^FT lines up with the bottom (letters standing on it).
Also note that ^CF changes the printer-wide default font, and there is no point to use it before each command. Use ^A instead as shown. You don't need to set ^CI before each command either, it is again a global setting for encoding of the entire label text.

How to do a zpl batch printing

I am able to print the labels by sending zpl commands to the printer.
Now how to do a batch printing of zpl labels programatically.
suppose if have multiple labels to be printed in a single printjob.
You should be able to simply send all the labels together as a single ZPL command string.
Just do an ^XZ command to end the current label
and then ^XA to start the next one.
If the batch of labels are all identical, you can just add the ^PQ command before the ^XZ. The ^PQ command is used to have a single label printed multiple times, so adding ^PQ50 would make the label print 50 times.
Here is an example that will generate a batch of 500 labels. It includes an increment number within a barcode which is also displayed as text.
^XA
^FO250,40^A0N,70,70^FDLPN^FS
^FO30,120^A0N,50,50
^BCN,100,N,N,N
^FD1000001^SFddddddd^FS
^FO200,300^A0N,50,50
^FD1000001^SFddddddd^FS
^PQ500
^XZ

Resources