How To: Printing directly to Networked Zebra Label Printers
Posted: Mon Aug 01, 2022 1:10 pm
Though this might useful for others, probably not perfect (and missing some errors handling) but functional
This was setup to allow any device on our company intranet to be able to print selected information from a nuBuilder record to a networked Zebra label printer.
Once you have a label template ready to use you need to get the code of the label in ZPL (Zebra Print Language) format. Label design programs should allow you to do this, I use Bartender 2016 and the print to file option, there is also the online Labelary ZPL Viewer which allows you to change the code and see the output directly.
So I have the following label Which has the following underlying ZPL code:
This label will print the Batch number, and the starting Pack Number, which in turn will autoincrement with each label printed until all labels in the print job have been printed. Take this code and save it to a nuBuilder procedure, lets call it , with the Run option set to hidden and best to set the procedure to have Global in the Access Level, so all users can access it. Obviously you can change this option if needed.
In this label there are three components I want to take the information from nuBuilder: the Thingy Batch Number (T0129 in the image), the Pack Number value (006 in the image), and the number of labels to print.
We will replace these with hash cookie values:
in the label code replace T0129 with
replace the 3 digit number in SN with
find PQ in the label code and replace the first 1 (this determines the number of labels to print) with to generate
Now we need to add the following code before all the labelling code
and the following after the labelling code
Here I have simply hardcoded the Zebra printer's IP and Port addresses (192.168.30.1 and 9100, respectively). This may work for some but not all. They can also be replaced with hash cookie values (if you have multiple Zebra printers available) and pull the information from nuBuilder. It is a setup I have in use here, as we have different Zebra printers for different sizes, but for the sake of clarity I'll leave that out of this example.
Next we need to put this code in the nuBuilder form for the end user to access.
In a Form, which has fields for tng_lot_number (the lot number), tng_batch_label_first (the number you want the Pack Number to start at), and tng_number_batch_labels (how many labels you want to print), fill the fields in as required.
Add a Print button for printing and change the Custom Code of the button to the following:
This will run the code to print the labels, then hide the button until the record is refreshed. I added this as a failsafe to prevent users pressing the Print button more than once accidentally/deliberately (especially on tablets), as it is usually used to print a few hundred labels at a time and there is no "Success" dialogue box, or option to cancel the job prior to printing. Once it's pressed it goes!
Hope this may be of use to others. If using mulitple printers I can tell you how I've achieved it if you want to know.
Thanks,
Paul

This was setup to allow any device on our company intranet to be able to print selected information from a nuBuilder record to a networked Zebra label printer.
Once you have a label template ready to use you need to get the code of the label in ZPL (Zebra Print Language) format. Label design programs should allow you to do this, I use Bartender 2016 and the print to file option, there is also the online Labelary ZPL Viewer which allows you to change the code and see the output directly.
So I have the following label Which has the following underlying ZPL code:
Code: Select all
^XA
^SZ2^JMA
^MCY^PMN
^PW626
~JSN
^JZY
^LH0,0^LRN
^XZ
^XA
^FT197,170
^CI0
^A0N,59,80^FDT0129^FS
^FT30,250
^A0N,42,64^FDPack Number:^FS
^FT440,256
^A0N,59,80^SN006,1,Y^FS
^FT37,94
^A0N,42,57^FDThingy Batch Number:^FS
^PQ1,0,1,Y
^XZ
Code: Select all
zpl_label
In this label there are three components I want to take the information from nuBuilder: the Thingy Batch Number (T0129 in the image), the Pack Number value (006 in the image), and the number of labels to print.
We will replace these with hash cookie values:
in the label code replace T0129 with
Code: Select all
'.$lot.'
Code: Select all
'.$startnum.'
Code: Select all
'.$numberlabels.'
Code: Select all
PQ'.$numberlabels.',0,1,Y
Code: Select all
$printer_ip = 192.168.30.1;
$printer_port = 9100';
$lot = '#tng_lot_number#';
$startnum = '#tng_batch_label_first#';
$numberlabels = '#tng_number_batch_labels#';
if(($conn = fsockopen($printer_ip,$printer_port,$errno,$errstr))===false){
echo 'Connection Failed' . $errno . $errstr;
}
$data = '
Code: Select all
';
#send request
$fput = fputs($conn, $data, strlen($data));
#close the connection
fclose($conn);
Next we need to put this code in the nuBuilder form for the end user to access.
In a Form, which has fields for tng_lot_number (the lot number), tng_batch_label_first (the number you want the Pack Number to start at), and tng_number_batch_labels (how many labels you want to print), fill the fields in as required.
Add a Print button for printing and change the Custom Code of the button to the following:
Code: Select all
nuRunPHPHidden('zpl_label',0);
var t = this;
nuHide(t.id);
Hope this may be of use to others. If using mulitple printers I can tell you how I've achieved it if you want to know.
Thanks,
Paul