如何使用android上的sdk打印到斑马打印机时设置标签变量的值

Min*_*ire 9 android zebra-printers

如何打印包含变量的预制标签(使用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();
 }
Run Code Online (Sandbox Code Playgroud)

Ovi*_*ler 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();
 }
Run Code Online (Sandbox Code Playgroud)

  • 标签设计应用程序lbl文件用于应用程序的GUI部分,字段的放置等.您需要将格式导出为ZPL文件,该文件看起来像上面的ASCII文本,夹在^ XA ^ XZ之间.要在打印机上获取ZPL文件,请在ZebraDesigner中单击文件 - >导出到打印机.(您必须正确设置打印机驱动程序)这将保存打印机上的格式.相反,如果您不希望它保存在您的打印机上,您可以将驱动程序设置为指向文本文件,抓取文本并每次发送文件,就像您在示例中所做的那样 (2认同)
  • 好的。尤里卡。现在工作顺利。再次感谢,希望有一天能够回报! (2认同)