Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the value of variables for a label when printing to a zebra printer using the sdk on android

How can one print a pre-made label (made using Zeba Label Designer) that contains variables and set those variables before printing.

I have the following code, but I am not sure how to set a variable (eg. I have a QR Code in the label I designed and I would like to set its data before printing).

TcpPrinterConnection zebraPrinterConnection = new TcpPrinterConnection("192.168.1.100", TcpPrinterConnection.DEFAULT_ZPL_TCP_PORT);
 try {
     ZebraPrinter printer = ZebraPrinterFactory.getInstance(zebraPrinterConnection);
     printer.getFileUtil().sendFileContents("/sdcard/documents/labels/sample.lbl");
     zebraPrinterConnection.close();
 } catch (ZebraPrinterConnectionException e) {
     e.printStackTrace();
 } catch (ZebraPrinterLanguageUnknownException e) {
     e.printStackTrace();
 } catch (ZebraIllegalArgumentException e) {
     e.printStackTrace();
 }
like image 822
MindWire Avatar asked Oct 11 '11 15:10

MindWire


People also ask

Why don't my labels print correctly on my Zebra printer?

The first cause of this issue is due to an incorrect setting in the printer's driver. To correct this problem, please do the following: Open the Start Menu and select "Devices and Printers", "Printers", or "Printers and Faxes". Right-click on the Zebra Eltron printer icon and select "Printing Preferences".


1 Answers

You need to look at the output from Zebra Label Designer to get your variables and then hook them up through the sdk

Checkout the documentation that came with the ZebraLink SDK, it has a bunch of good examples on how to print stored formats. Here's one of the examples. In this example, the "First Name" variable is number 12. The "Last Name" variable is number 11.

 ^XA
 ^DFE:FORMAT.ZPL
 ^FS
 ^FT26,243^A0N,56,55^FH\^FN12"First Name"^FS
 ^FT26,296^A0N,56,55^FH\^FN11"Last Name"^FS
 ^FT258,73^A0N,39,38^FH\^FDVisitor^FS
 ^BY2,4^FT403,376^B7N,4,0,2,2,N^FH^FDSerial Number^FS
 ^FO5,17^GB601,379,8^FS
 ^XZ

 TcpPrinterConnection zebraPrinterConnection = new TcpPrinterConnection("192.168.1.32", TcpPrinterConnection.DEFAULT_ZPL_TCP_PORT);
 try {
     zebraPrinterConnection.open();
     ZebraPrinter printer = ZebraPrinterFactory.getInstance(zebraPrinterConnection);
     Map<Integer, String> vars = new HashMap<Integer, String>();
     vars.put(12, "John");
     vars.put(11, "Smith");
     printer.getFormatUtil().printStoredFormat("E:FORMAT.ZPL", vars);
     zebraPrinterConnection.close();
 } catch (ZebraPrinterConnectionException e) {
     e.printStackTrace();
 } catch (ZebraPrinterLanguageUnknownException e) {
     e.printStackTrace();
 }
like image 100
Ovi Tisler Avatar answered Oct 19 '22 23:10

Ovi Tisler