【问题标题】:Printing ZPL in Windows 7 with a usb connected Zebra printer使用 USB 连接的 Zebra 打印机在 Windows 7 中打印 ZPL
【发布时间】:2013-01-28 16:52:58
【问题描述】:

我正在尝试从 Windows 7 中的 Java 应用程序将一些 ZPL 代码发送到通过 USB 连接的 Zebra TLP 2824。我尝试了不同的方法,但还无法打印。在驱动程序设置中,我激活了直通模式并尝试使用通用/文本模式驱动程序安装打印机,但没有任何效果。

我总是在打印队列中遇到未指定的 Windows 错误。

这是我的代码:

        try {

           PrintService psZebra = null;
           String sPrinterName = null;
           PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

           for (int i = 0; i < services.length; i++) {

               PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
               sPrinterName = ((PrinterName) attr).getValue();

               if (sPrinterName.toLowerCase().indexOf("generic") >= 0) {
                   psZebra = services[i];
                   System.out.println(psZebra);
                   break;
               }
           }

           if (psZebra == null) {
               System.out.println("Zebra printer not found.");
               return;
           }
           DocPrintJob job = psZebra.createPrintJob();

           String s = "${^XA^FO100,100^BY7^BCN,100,Y,N,N^FD123456^FS^XZ}$";

           byte[] by = s.getBytes();
           DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
           Doc doc = new SimpleDoc(by, flavor, null);
           job.print(doc, null);

       } catch (PrintException e) {
           e.printStackTrace();
       }   

【问题讨论】:

    标签: java usb zpl


    【解决方案1】:

    似乎我很接近。我的打印机不支持 ZPL,我不得不使用 EPL2 代码。另一件事是使用InputStream 而不是byteArrays

    这就是变化:

    DocPrintJob job = psZebra.createPrintJob();
    
    String s =  "N"+"\n"+
            "q305"+"\n"+
            "Q203,26"+"\n"+
            "B55,26,0,1,2,2,152,B,\""+code+"\""+"\n"+
            "P1,1";
    
    InputStream is = new ByteArrayInputStream(s.getBytes());
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc doc = new SimpleDoc(is, flavor, null);
    
    job.print(doc, null);
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    } 
    

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多