ZPL Exercises

Index:

  1. Introduction

  2. Setup

  3. Exercises

  1. Print your name on the label

  2. Boxes and lines

  3. Barcodes

  4. Serial number commands

  5. Saving a template to memory

  6. Printing graphics

  7. Printing true type fonts

Introduction:

The purpose of these exercises is to introduce some basic ZPL commands to new users.

Setup:

Its important to understand that 200 DPI means the resolution of the printhead is 200 dots per inch.  If you program the printer to draw a line 100 dots long that will equal a half inch. 100 dots on a 300 DPI printer will print a line 1/3" long.

Also it is important to know that the home position that all your coordinates are referencing is at the left hand trailing edge of the label as the label comes out of the printer. (There are some exceptions to this.)

Exercises will start simple and gradually progress to give you an opportunity to try a large variety of commonly used ZPL commands. All commands will not be covered but this should be a good core of commands to learn. Some commands may not be supported due to firmware version in your printer.

Exercise 1

Print your name on the label

Start by printing just your name on the label using the following format as a model.

^XA
^FO50,50^ADN,36,20^FDxxxxxxxxxxx^FS put your name where the x’s are
^XZ

Send the above format to the printer.

^XA every format must start with this command
^XZ every format must end with this command
^FD     field data
^FS     field seperator

Field origin

^FO

After the label has printed correctly alter the first number after the FOx and see how that effects the print position.

Then alter the second number after the FO50,x and see how that effects the print position.

Font instruction

^ADN

Next alter the numbers after the ^ADN,x,x command.
18,10 is the smallest size you can make the D font.
First number is the height of the font in dots and the second is the width.
You can use direct multiples up to ten times that size as a max…for example 180,100 is the largest you can make the D font.
25,18 would not be a valid size. The printer will round to next recognizable size.
Check the ZPL programming guide to see the font matrices tables to try other fonts.
Try the zero scalable font ^A0N,x,x This font is scalable and you can choose any height and width.

Rotation commands

Next change ^ADN to^ADR, then^ADI, then^ADB
Note how the print position changes
Add some more fields
Next add two more fields to print directly under your name using the ^ADN,36,20 font and size

Your street address
Your city, state, zip

You will need to add two more lines of code that will start off with:

^XA
^FO50,50^ADN,36,20^FDxxxxxxxxxxx^FS
^FO    (fill in the rest)
^FO    (fill in the rest)
^XZ

Make sure all three fields print in same font and size and left side of fields has same vertical alignment.

Your name
1200 W Main Street
Anytown, Il 60061

Exercise 2

Boxes and lines

Use the address format from exercise one.
Start by adding this new line to your existing format:
^FO50,200^GB200,200,2^FS
This will print a box one wide by one inch long and the thickness of the line is 2 dots.
Next reposition and resize the square so that it goes around the name and address uniformly.
Next print a line by adding

^FO50,300^GB400,4,2^FS

This will print a horizontal line two inches wide by 4 dots thick.
Change the format for the horizontal line so that it is one inch wide and is printed on the very center of the label.
Then add some ZPL to produce a vertical line over your horizontal line so it looks like a plus symbol.

Exercise 3

Barcodes

^B3 code 39 barcode
Start a completely new format in ztools.
Write the following format and send to the printer:

^XA
^FO50,50^B3N,N,100,Y,N^FD123456^FS
^XZ

Consult the ZPL programming guide and try changing each of the variables in the ^B3 string so you can see the effects.

^B3o,e,h,f,g
^BY

Insert the ^BY command just before the ^B3 command so you can see how the narrow bar width can be altered.

^FO50,50^BY2^B3..etc ^BYx, acceptable values for x are 1 through 10

Next alter the ratio of the narrow to wide bar.
^FO50,50^BY2,3^B3..etc ^BY2,x acceptable values for x are 2.1 through 3 in .1 increments
Print out a ^B3 barcode with the interpretation line on top of the barcode and the barcode rotated 90 degrees.
^PQ Print quantity command
Add a ^PQ command just before the ^XZ to print several labels.

^PQ4
^XZ

^PR Print rate (in inches per second)
Add a ^PR command just after the ^XA at the beginning of the format to change the print rate (print speed).

^XA

^PR4 then try ^PR6 ^PRx acceptable values for x are 2 through 12 (check printer specs)
Note how the print speed effects the print quality of the barcode. You may need to increase the printer darkness setting at higher print speeds.

Exercise 4

Serial number commands

^SN serial number
Send this format to the printer:

^XA
^FO100,100^ADN,36,20^SN001,1,Y^FS
^PQ3
^XZ

Consult the ZPL programming guide and vary the ^SNv,n,z to exercise the increment/decrement and leading zeros functions.

^SF

If your serial number contains some alpha and numeric characters you can increment or decrement a specific segment of the data even if its in the middle like the sample sequence shown below:

ABCD1000EFGH, ABCD1001EFGH, ABCD1002EFGH

Send this file to the printer and you will see how it increments the serial number. The ^SF command can also work with alpha characters.

^XA
^FO100,100^ADN,36,20^FDABCD1000EFGH^SF%%%%dddd%%%%,10000^FS
^PQ15
^XZ

Note how the field data character position aligns with ^SF data string:

^ F D A B C D 1 0 0 E F G H
^ S F % % % % d d % % % %
1 0 0 0 0
2 0 0 0 0
3 0 0 0 0

And on through....

1 0 1 4 0 0 0 0

Last label will print ABCD1014EFGH

The % is placed in positions that you do not want to increment/decrement, d = decimal, 10000=increment value.

Consult the ZPL programming guide for more details on the ^SF command.

Exercise 5

Saving a template to memory

^IS and ^IL image save and image load

Send this format to the printer:
Since there is a lot of data to type in this exercise you are likely to make a typo so it also becomes an exercise to troubleshoot your code against the errors you see on your labels.

^XA
^FO20,30^GB750,1100,4^FS
^FO20,30^GB750,200,4^FS
^FO20,30^GB750,400,4^FS
^FO20,30^GB750,700,4^FS
^FO20,226^GB325,204,4^FS
^FO30,40^ADN,36,20^FDShip to:^FS
^FO30,260^ADN,18,10^FDPart number #^FS
^FO360,260^ADN,18,10^FDDescription:^FS
^FO30,750^ADN,36,20^FDFrom:^FS
^ISR:SAMPLE.ZPL^FS
^XZ

Next send this format:

^XA
^ILR:SAMPLE.ZPL^FS
^FO150,125^ADN,36,20^FDAcme Printing^FS
^FO60,330^ADN,36,20^FD14042^FS
^FO400,330^ADN,36,20^FDScrew^FS
^FO70,480^BY4^B3N,,200^FD12345678^FS
^FO150,800^ADN,36,20^FDMacks Fabricating^FS
^XZ

In this way the template only needs to be sent one time to the printers memory.  Then subsequent formats can be sent recalling the template and merging variable data into the template.  In this case the file was saved in the printers R: memory which is volatile.

^DF and ^XF

Download format and recall format

Similar concept to ^IS and ^IL command. ^IS and ^IL in general processes faster in the printer then ^DF and ^XF. Some applications customers may prefer ^DF/^XF.

This is the way the ^DF and ^XF formats would look to produce a similar label to the ^IS/^IL sample you just tried.

^XA
^DFR:SAMPLE.ZPL^FS
^FO20,30^GB750,1100,4^FS
^FO20,30^GB750,200,4^FS
^FO20,30^GB750,400,4^FS
^FO20,30^GB750,700,4^FS
^FO20,226^GB325,204,4^FS
^FO30,40^ADN,36,20^FDShip to:^FS
^FO30,260^ADN,18,10^FDPart number #^FS
^FO360,260^ADN,18,10^FDDescription:^FS
^FO30,750^ADN,36,20^FDFrom:^FS
^FO150,125^ADN,36,20^FN1^FS  (ship to)
^FO60,330^ADN,36,20^FN2^FS (part num)
^FO400,330^ADN,36,20^FN3^FS (description)
^FO70,480^BY4^B3N,,200^FN4^FS   (barcode)
^FO150,800^ADN,36,20^FN5^FS  (from)
^XZ

 

^XA
^XFR:SAMPLE.ZPL
^FN1^FDAcme Printing^FS
^FN2^FD14042^FS
^FN3^FDScrew^FS
^FN4^FD12345678^FS
^FN5^FDMacks Fabricating^FS
^XZ

Exercise 6

Click here to see creating graphic files with the Zebra Driver

 

Converting a .pcx Graphic file to .grf using Ztools Utility.

Note: The .pcx and must be in black and white.

4 Memory types of printer memory:

To see what memories are available in your printer you can print a configuration label to see the listing. Consult your users guide to print a Configuration label (power up cancel test).

R: DRAM: files stored here will be cleared if printer is turned off.

B: PCMCIA card: (non volatile memory-standard on some models and optional on others).

E: Flash memory: (non volatile memory-standard on some models and optional on others).

A: Compact Flash (non volatile memory-standard on some models and optional on others)

Once you have Ztools installed follow steps below to create a .grf graphic:

  1. Next click on OPTIONS/ DIRECTORIES. The DESTINATION field indicates what directory the .grf file is saved in. Click on OK to get out of that window once you’ve noted the destination path.
  2. Click on CONVERT in the tool bar.
  3. Click on GRAPHIC in drop down window.
    In the next drop down window you will see R:. If you want the converted file to eventually go the printers volatile memory then leave R: selected.
  4. For this example we will choose B:.
  5. Next click on BROWSE and find the .tif or .pcx file and click on it. You should see the blanks fill in for Source, Destination, and ZPL name in the window.
  6. Click on CONVERT. You should see another application open on Win 95 that displays MSDOS Finished.
  7. If you open MSDOS Finished it will say Finished-zimaglit with couple lines of info. As long as you do not see an error message then the file should have successfully converted to a .grf file.
  8. Exit MSDOS Finished. Exit Convert graphic file window.
  9. Click on FILE/OPEN, go to directory you noted in step 1, and click on list files of type dropdown and choose all files (*.*). Scroll through files till you find your file with .grf extension, choose it and click on OK. You should see a display similar to the following:

    ~DGB:MAINT,24336,078,00000000000000000000000000000000000000000000000000000
    00000000000000000000000000000000000000000000000000000000000000000000000000
    00000000000003FE0000000000000000000000000000000000000000000000000000000000
    00000000000000000000000000000000000000000000000000000000000000000000000000
    00000000000001FFFFE000000000000…etc…

NOTE: If you want this graphic to be downloaded to printer flash memory (E:) then edit file. Replace the ~DGB: with ~DGE: and save.

  1. Next click on OPTIONS/PORTS in the tool bar. If you choose comport (serial) then make sure communication parameters match printers comm parameters….baud, databits, parity, stop bits, and host handshake. If you are using lpt (parallel) port then choose the correct lpt numbered port. Click on OK.
  2. The power light should be the only light that’s turned on our printer front panel. In the Ztools tool bar click on the green traffic light. You should see the data light flashing on the front of our printer for the duration of the download and when complete the data light will stay off. 
  3. There are two ways to check and see if the .grf file got to the printer intact:
  1. If the printer has a lcd display go to LIST IMAGES and click on PRINT.
  2. If printer does not have LCD display you can create a text file in Ztools as shown below and send it to the printer by clicking on green traffic light.

^XA^WDB:*.*^XZ

The printer should print an index onto the labels that looks somewhat like this:

Directory of B:*.*

B:MAINT.GRF 24356 (BYTES)

And then the number of bytes that are still unused.

  1. Then you can create a short zpl file in Ztools to see if the graphic will print onto your labels.

^XA^FO50,50^XGB:MAINT.GRF^XZ

Use the green traffic light to send that string to the printer and graphic should print onto label.

In the various ZPL string samples above you will have to replace the B: portion with either R: or E: or A depending on where the graphic is to be stored and retrieved from.

Exercise 7

Converting and printing true type fonts with ZTOOLS Utility

Downloading and printing true type fonts with the Zebra Universal Driver

4 Memory types

To see what memories are available in your printer you can print a configuration label to see the listing. Consult your users guide to print a Configuration label (power up cancel test).

R: DRAM: files stored here will be cleared if printer is turned off.

B: PCMCIA card: (non volatile memory-standard on some models and optional on others).

E: Flash memory: (non volatile memory-standard on some models and optional on others).

A: Compact Flash (non volatile memory-standard on some models and optional on others)