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();
}
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".
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With