使用 Zebra Link-Os SDK 打印

Printing with Zebra Link-Os SDK

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

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

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

请尝试使用以下代码:

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

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

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

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?
        }