我正在使用此代码将图像打印到斑马打印机。
ZebraPrinterConnection connection = new TcpPrinterConnection(ipAddress,port);
connection.Open();
ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);
printer.GetGraphicsUtil().PrintImage("imageAddress");
它工作正常,但有时打印机不打印,在代码中我没有得到任何错误。有没有办法检查标签是否在物理上打印?
答案 0 :(得分: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?
}
答案 1 :(得分:0)
请尝试使用以下代码:
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);
}