Okay maybe the title is a bit of an exaggeration. But if you've ever needed to control a label printer in a LabVIEW application, you may have run into some weird behavior or limitations. This blog post is intended to help give a guide on the ways to control a Zebra label printer, along with the various techniques I've used over the years to create templates, make labels, and preview them before printing.
Zebra Setup Utility
All Zebra printers seem to use a single set of drivers for controlling printers. This is the Windows Printer Driver available on their downloads page. After installed the Zebra Setup Utilities will be in the start menu. This is the basic utility for installing and uninstalling printers, along with basic control. This is a great simple utility for making sure the basic communication with the printer is working.
Zebra Designer
This is where the fun starts. Zebra Designer 3 is a program for designing labels to send to Zebra printers. It is a fairly robust program allowing for lots of customization. You drag objects around, resizing, create barcodes, and can import images and logos.
The Zebra Designer software is free to use with basic function, and then licenses some extra things like database connectivity. I've honestly never used the pro version of Zebra Designer because the pro features aren't needed if you know how to program. I can see the benefit of having an excel file, full of barcodes to print, and then have Zebra Designer look at the excel file, and send a label for each entry. But if you are controlling this printer from a LabVIEW program, it isn't hard to just create a FOR loop, and then send print commands with different files.
I'm not going to go over all features of the Zebra Designer software, but a few things you may need to check are in the print settings. I have to check these most times I print something because it seems they often change back to the default. Once you have a label on the right material size, and for the right printer, click on Print, or go to File >> Print. Then click Print Settings. Under Advanced Setup is the various settings for your printer. Often in production environments the printer is configured to peal off each label as it prints on the Thermal Transfer material. Some Zebra printers have an optional pickup wheel that will pull the label material over a bar pealing them one at a time. Without this setting it just prints to a single label one at a time. Just select the right print options for your setup. If it does peal you need to tell the printer how to reverse, or even if it should. This is the Backfeed settings and I find the Before Printing to be the best. This will cause the printer to reverse just a bit before printing, then print and peal. This is accessed from the Other menu.
Another fun setting here is the Use Zip Compression for Graphics. I'll get into this more later but if this is unchecked the graphics on a label will be sent as raw bytes. Most settings I would leave as Use Printer Settings if you can. Things like offset, adjustments, and darkness are all important settings, but I think it is best to just use the settings on the printer itself. This way if adjustments need to be made, they can be done with the front controls of the printer, and not needing to set settings in the print file. There are pros and cons to this of course and your needs might be different.
With all the settings correct click Print and test that it prints correctly. If it does, then check the Print to File, and try printing again. Now a dialog will come up asking where to save the print file. Save this PRN file, and then open it in a text editor.
ZPL and PRN
Open the PRN file and it will look something like this:
CT~~CD,~CC^~CT~
^XA~TA000~JSB^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR6,6~SD15^JUS^LRN^CI0^XZ
^XA
^MMP
^PW900
^LL0600
^LS0
^FO576,96^GFA,13312,13312,00032,:Z64:[Data Blob]Y:A04F
^FT68,182^A0N,98,67^FH\^FDBarcode: ABC123^FS
^BY276,276^FT87,519^BXN,23,200,0,0,1,~
^FH\^FDABC123^FS
^PQ1,0,1,Y^XZ
Here we can see the print commands that go out to the printer, line by line. These commands are documented in the Zebra ZPL Programming Guide. You can take this PRN file and send it to the printer, using the Zebra Setup Utility as mentioned earlier. This will send the commands to the printer and you should get an identical label. If you look at the PRN text file you can see things like ^FDBarcode: ABC123^FS, and ^FH\^FDABC123^FS. These are are data fields with fixed data in them. The first is the text "Barcode: ABC123" and the second is the data matrix barcode "ABC123". If these fields are edited, before being sent to the printer, then the new data will replace the old one. This is a common technique of generating a label template, with fields in it that will be populated with live data. There is an online ZPL viewer at Labelary.com which allows uploading a PRN file, or pasting in the ZPL commands. This website is very helpful for understanding commands, and the descriptor at the bottom of the page changes based on where the cursor is in the text.
Printing With LabVIEW
Okay so now we installed the Zebra printer, we are familiar with the basics of the Zebra Setup Utility, we installed the Zebra Designer software, we made a template that we can print, and we made a PRN file from that template that we can send to the printer. The last step in automating the control of this printer is programmatically editing the PRN file, then sending it to the printer all from LabVIEW. There are a few options.
Notepad and Text Driver
If you simply send the PRN file to a Zebra printer, as if it were any normal printer, it won't send the text as commands. It will send them as lines of text to be printed. So the first solution I saw online was to install the printer with a Generic Text Printer Driver in Windows, then use Notepad and a command line to send the command to the printer. Here is the article on Zebra's website on how to install a printer with the Generic Text Only driver, then use Notepad to print to this which will result in the label being printed. Here is a post on NI's forums where this is discussed and an example posted.
This method works but has several limitations. First I noticed that images weren't being printed on the label. But the same PRN file being sent with the Zebra Setup Utility worked just fine. The fix was in the Zebra Designer settings. As mentioned in the Print Settings there is an option to Use Zip Compression. If this is on I believe there are bytes in the file that aren't interpreted correctly. To get it to print correctly I needed to uncheck this setting, then recreate the PRN file. Another issue I had with this is when a printer was replaced with a new one, the custom generic driver needed needed to be picked for that new printer. And lastly there is no feedback from the printer or Notepad. If the printer name is incorrect for instance nothing will happen and there is no feedback that the label wasn't printed correctly.
Windows Print Command
The next technique is an improvement on the last. Windows has a command line Print function, that works for network printers. After installing the printer in the Zebra Setup Utility, go to Devices and Printers in Windows under the Control Panel. Find the printer, right click and go to Printer Properties, (not the Properties at the bottom but "Printer Properties"). From here go to the Sharing tab, then share the printer giving it a name like Zebra1.
Now that the printer is shared, we can use the print command:
print /D:"\\localhost\Zebra1" "C:\temp\label.prn"
This will send the label.prn file to the local computer, to the Zebra1 printer name we shared earlier. This is an improvement because we no longer need a Generic Text driver, the graphics setting in Zebra Designer can use Zip compression, and the command line function will return some kind of response for things like the printer not being available.
Sharp Zebra API
The last option is the best so far. Over on github is a project by rkone called SharpZebra. This is a .Net driver for interfacing with Zebra printers. The only release at the moment on github is the 1.1.0 of the SharpZebraStandard package. I could not get this version to work in LabVIEW. I'm not a .Net expert and am unsure why, but some of the Objects weren't loading which were necessary. After digging into it some more I found that there are actually 3 different releases over on nuget.org.
- SharpZebraStandard: based on .NET Standard 2.0, for versions of .NET 5 and higher. Can only print to network based printers.
- SharpZebraStandard.DesktopPrinting: For projects using .Net 4.7 to 4.8.2. For Windows projects that would like to print via USB or printers installed in the Windows Printers panel.
- SharpZebra.rkone: For older projects using .NET 2.0 - 4.6.2 (.NET classic). No longer being updated with new features. This is the one that works in LabVIEW
After some testing I can only get the SharpZebra.rkone to work in LabVIEW. I suspect there is an issue with .Net versioning, but regardless it seems to function correctly in modern Windows and LabVIEW versions. Some versions won't load the assembly in LabVIEW, and some appear to be missing the SpoolPrinter Object. At the moment the newest version that I've had success with is version 1.0.6 of the SharpZebra.rkone. Here is some example code on using it:
In some cases downloading a DLL will cause Windows to block the file for protection. If this happens then things might not load in LabVIEW correctly. Be sure and check that the DLL is Unblocked in Windows Explorer. In most cases you can just right click the DLL, check the Unblock, and apply, if the checkbox exists.
This method is improved over the previous two for several reasons. No custom drivers are needed, or custom settings and specific names on install of the printer. Some level of plug and play or auto detection can be used. This method has some level of error handling, and response from the printer. Additionally functions like this one can be used to get a list of the installed printers on the computer. This way we can query the printers on the PC, then find the default one, or if there is only one, and use that name in the SharpZebra API. And it works in LabVIEW 32 or 64 bit, in LabVIEW 2022 Q3, and Windows 10 or 11. When calling random DLLs and .Net functions in LabVIEW, compatibility can be an issue.
Print N Labels
With all of this available it is now straightforward to take an existing PRN file as a template, edit it, and send it to be printed. Here is a code snippet showing how to print N different labels, by editing the ABC123 text, to be unique. I've included this, along with the printer finding code, and the Zebra Sharp examples in this attachment. This works well because the text for the label, as well as the 2D barcode, is stored in the PRN as plain text. Performing a search and replace, replacing all instances of ABC123 with ABCXXX will replace the label, and update the barcode.
Preview Label
Before printing a label to a printer, I find it useful to sometimes be able to see what the label would look like if it were to be printed. There are a few options for this. The quick solution if you have access to the internet is to use a service like the one on Labelary. I already mentioned this earlier, and it works if you have a single label and don't mind manually pasting things, or selecting file. It has options for label size, resolution, and you can quickly see the changes before printing. It also is helpful in knowing what the various commands can be used. Near the bottom a description will talk about the function that the cursor is on.
This is nice and all but I also wouldn't mind being able to see labels from within LabVIEW. Then you might be able to show the label before printing, or be able to query a database entry of labels. Some APIs have a license cost, and there are some online open source alternatives. I'm not happy with the amount of external code this solution uses, but it does work and I wanted to share it since I couldn't find any other usable solution. Download the example here, extract it, and open the only VI in it. The ZPL example from Labelary is in the VI as the default so you can just run the VI to see the results. This will make a temporary file, then run a command line call to generate the PNG for the print commands.
Other Printer Options
I haven't fully explored other printers, but the ZPL standard is common enough that other printer makers have adopted some level of emulation to support it. Wasp is another maker of printers intended for labeling. They have their own tools for making labels, and have their own printer language called WPL. In addition to this they support some open source label making software like gLabels. But they also support built in emulation for ZPL, ELP, and DPL. What this means is a label can be made in the Zebra Designer software, printed to a PRN, and then sent to another lower cost printer like Wasp.
Conclusion
Zebra printers certainly have their quirks. I haven't even touched on the hardware side of things, where sensors get dirty, labels are misaligned, belts skip, or random errors. But at least if you have a working hardware setup, this blog post should help understand the control capabilities.



