9

如何打印包含变量的预制标签(使用 Zeba Label Designer 制作)并在打印前设置这些变量。

我有以下代码,但我不确定如何设置变量(例如,我设计的标签中有一个二维码,我想在打印前设置它的数据)。

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();
 }
4

1 回答 1

7

您需要查看 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,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();
 }
于 2011-10-11T19:55:23.637 回答