如何打印包含变量的预制标签(使用Zeba Label Designer制作)并在打印前设置这些变量.
我有以下代码,但我不知道如何设置变量(例如,我在我设计的标签中有一个QR码,我想在打印前设置其数据).
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(); }
解决方法
您需要查看Zebra Label Designer的输出以获取变量,然后通过sdk将它们连接起来
查看ZebraLink SDK附带的文档,它有很多关于如何打印存储格式的好例子.这是其中一个例子.在此示例中,“First Name”变量为数字12.“Last Name”变量为数字11.
^XA ^DFE:FORMAT.ZPL ^FS ^FT26,243^A0N,56,55^FH\^FN12"First Name"^FS ^FT26,296^A0N,55^FH\^FN11"Last Name"^FS ^FT258,73^A0N,39,38^FH\^FDVisitor^FS ^BY2,4^FT403,376^B7N,4,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(); }