How to set variable value for label when printing to zebra printer using sdk on android

How to print a pre-made shortcut (made using Zeba Label Designer) that contains variables and set these variables before printing.

I have the following code, but I'm not sure how to set the variable (for example, I have a QR code in the shortcut that I created, 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(); } 
+9
android zebra-printers
source share
1 answer

You need to look at the result of Zebra Label Designer to get the variables and then connect them via sdk

Check out the documentation that comes with the ZebraLink SDK, there are tons of good examples on how to print saved formats. Here is one example. In this example, the variable "First Name" is number 12. The variable "Last Name" 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(); } 
+7
source share

All Articles