【问题标题】:Printing with Zebra Link-Os SDK使用 Zebra Link-Os SDK 进行打印
【发布时间】:2017-02-07 15:26:29
【问题描述】:

我正在使用此代码将图像打印到斑马打印机。

ZebraPrinterConnection connection = new TcpPrinterConnection(ipAddress,port);
connection.Open();
ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);
printer.GetGraphicsUtil().PrintImage("imageAddress");

它工作正常,但有时打印机不打印并且在代码中我没有收到任何错误。有没有办法检查标签是否实际打印?

【问题讨论】:

    标签: c# image printing sdk zebra-printers


    【解决方案1】:

    有几种方法可以做到这一点。

    第一种方法是在打印期间/之后检查状态并确认缓冲区中没有字节并且打印机上没有错误:

    private boolean postPrintCheckPrinterStatus(Connection connection)
    {
        ZebraPrinter printer = ZebraPrinterFactory.getInstance(PrinterLanguage.ZPL, connection);
        PrinterStatus printerStatus = printer.getCurrentStatus();
    
        // loop while printing until print is complete or there is an error
        while ((printerStatus.numberOfFormatsInReceiveBuffer > 0) && (printerStatus.isReadyToPrint))
        {
            printerStatus = printer.getCurrentStatus();
        }
        if (printerStatus.isReadyToPrint) {
            System.out.println("Ready To Print");
            return true;
         } else if (printerStatus.isPaused) {
            System.out.println("Cannot Print because the printer is paused.");
         } else if (printerStatus.isHeadOpen) {
            System.out.println("Cannot Print because the printer head is open.");
         } else if (printerStatus.isPaperOut) {
            System.out.println("Cannot Print because the paper is out.");
         } else {
            System.out.println("Cannot Print.");
         }
        return false;
    }
    

    检查这一点的另一种方法是使用打印机里程表来确保标签已打印。前后检查里程表:

    // Set settings, check status, print, etc.
            if (setPrintLanguage(statusConnection) && checkPrinterStatus(statusConnection))
            {
                int labelCount = Integer.parseInt(SGD.GET("odometer.total_label_count", statusConnection));
                // Send Print Job (1 label)
                String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
                printerConnection.write(zplData.getBytes());
    
                if (postPrintCheckPrinterStatus(statusConnection))
                {
                    int newLabelCount = Integer.parseInt(SGD.GET("odometer.total_label_count", statusConnection));
                    if (newLabelCount == labelCount + 1)
                    {
                        System.out.println("Print Successful.");
                    }
                }
                //else reprint?
            }  
    

    【讨论】:

      【解决方案2】:

      请尝试以下代码:

      id<GraphicsUtil, NSObject> graphicsUtil = [zebraPrinter getGraphicsUtil];
      UIImage* image = [UIImage imageNamed:@"ImageName"];
      
      BOOL success = [graphicsUtil printImage:[image CGImage] atX:155 atY:0 withWidth:200 withHeight:80 andIsInsideFormat:NO error:&error];
      
      if(error) {
         NSLog(@"ERROR: %@", error);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-28
        • 1970-01-01
        • 1970-01-01
        • 2018-11-16
        • 1970-01-01
        相关资源
        最近更新 更多