Send ZPL command to Zebra 170PAX4 via TCP/IP Socket

You have to import the Socket class from Java.

1 Like

Please note that there is a much simpler way to communicate with Zebra nowadays using HTTP.


Many many thanks for your response.
I am going to read that one too!!

I believe there is going to be a Zebra printer module released very soon. Not by me, but soon, very soon.


REALLY!!! You have peaked my interest…

Also, really cool API I found is it can be used to preview ZPL code to images and has a nice webservice. I have used it in Ignition to preview labels before sending them to a printer.


Thanks for the HTTP tip. I did not know this was possible this easily.

Here is an Ignition snippet for reference that prints ZPL to a printer'', postData="^XA^WD^XZ")

Also check out their SDK.
The printers now have JSON out of band management on port 9200. They should also come with Bluetooth and RFID sticker on the side, at least for the ZT410s.
We have done a lot of work around this. At one point we had a simple iPhone app that our techs could run whenever they needed to provision a printer. The app sent all the necessary payloads to configure the printer, point it back to an FTP server (Zebra Mirror) for firmware updates. etc. Another thing we tried is to put the label templates on each printer and send XML print jobs direct over HTTP, but without a management tool it was a hassle and we settled on NiceLabel. Coincidentally Zebra’s label designer is a stripped down OE version of NiceLabel. NiceLabel software is nice, but their support sucks, and development is in Europe.

… and then we got pissed at Zebra and moved to Honeywell. In the end a printer is a printer is a printer. But the techs do miss the app.

Let me know if I can help more with these printers.


Thank you so much for your help:
I was able to print by pressing a button on Igniton:
All I needed to do was set the following code on the Script Editor of the mousedPressed* and I was able to print Hello World! hahaha. Thank you guys.‘’, postData="^XA^FO50,50^A0N50,50^FDHello World!^FS^XZ")

By the way, this is a great tool for generating the zpl code you need: Labelary Online ZPL Viewer
Thanks for sharing!!

1 Like

I think I posted a video about our solution before, but here it is again.

1 Like


I need to preview a label before printing like you

can you tell me how you did it?

I use an image component with the Labelary url in the Image Path.Works pretty slick. Here’s a sample window for you.

test_LabelPreview_2018-08-01_0804.proj (5.8 KB)


^ what he said :slight_smile:

here is the function I use to get the preview image formatted for an Ignition Image path. depending on how I am using it, I either return it as a image path or wrapped in HTML for embedding in other things.

def getPreview(zpl, png=True):
	import urllib

	if zpl:
		zpl = zpl.replace('\r', '').replace('\n', '').replace('\t', '')
		zpl = urllib.quote(zpl, '^:~,')
		url = "" % zpl
		if png:
			return url
			return "<html><img style='width:100%; height: auto;' src='" + url + "' /></html>"
		return ''

I am trying to print to a Zebra ZD410. I have used this snippet-‘’, postData="^XA^WD^XZ")

I cannot get the printer to do anything. I am able to ping it, and can print to it directly with the Zebra Setup Utility.
I have a TCP device driver setup for port 6101.
Can anyone help me out with what we may be missing here?


Put something like this in a project script:

import socket, sys
def sendToZebra(payload):
	zebraAddr = ('', 6101)
		s = socket.connect(zebraAddr)

Then call it from your button event like so:


Not tested precisely as above, but I use this pattern at a customer site. NOTE: No driver required.

Awesome! I will give it a try. Thank you!

Sorry maybe I should make a new post but my question rides right here along the path of this post.
I have a project in perspective where I need to print a small label, I would love to print usb but it doesn’t look like that is viable option. I have followed the rabbit to the zebra ZPL implementation where I would send a payload to the printer over the network. Looking for anymore success that anyone has had using perspective to print a label. I do not want to render a pdf and rely on the user to choose printing the pdf on the OS either.

As long as the gateway has access to the printer, there should be no issue using ZPL.

1 Like

In the one post by malcolm I would like to send the image of the container to the label.
I will use dropdown menus to populate the values in the container but there are also some graphics, mainly a logo. I also see the other fellow with the zebra API. That looks interesting. I have not decided if perspective is a good application for this or not. Even usb printers have setup involved so I dont know why I am hung up on usb other than past experience and usual lack of ethernet ports not consumed by something. doing the http post sound possible but its the payload being a graphic container. Maybe that is the part I dont understand. How to render a container with other variable content into this ZPL. I am not familiar with ZPL. It surely isn’t a simple as passing the container as an object into some script payload…?

@tailfire One thing you can do is download Zebra’s label design software called ‘ZebraDesigner’ as well as Zebra setup utilities. Then what you do is design the label in the ZebraDesigner, then change some settings to output the ZPL code for your label to a file rather than sending it to the printer. Then you can copy and paste the ZPL code into a script in perspective. In your script you can insert the data that the user selected into the label’s code before you send the code to the printer. In order to send the code to the printer (assuming your printer is on your network) you can create a socket in your script, connect to the printer using its IP, then convert your ZPL code string to bytes and send it to the printer using the socket.

To send the code to a file you open Zebra Setup Utilities, open Printer Tools for your printer, and change the port to “print to file”. If you google how to send ZPL code to file using ZebraDesigner you should be able to find more information (that’s how I learned about this).

Hope this helps!

1 Like

What I did was put easily recognizable values for each part of my label, so that when I looked at the code they were easy to find and modify for my script. here is a simple example that puts a few strings on a label as well as writes to an RFID tag:

^FT159,1078^A0N,83,132^FB433,1,21,C^FH\^CI28^FDthis is my string^FS^CI27

Then I could modify the code to look like this:


and insert the values that I actually want on the label using python’s str.format function before I send the code to the printer.