【问题标题】:How to adjust feed length to match image height on Zebra iMZ320 Printer如何在 Zebra iMZ320 打印机上调整进纸长度以匹配图像高度
【发布时间】:2017-05-26 04:55:48
【问题描述】:
我正在使用 Zebra iMZ320 打印机。我正在尝试通过 Android 设备上的 Zebra Utilities 应用程序打印 PNG 图像。有没有办法调整提要的长度以匹配图像高度而不拉伸图像?目前,我使用 Zebra Setup Utility 发送到打印机的唯一命令是:
! U1 "ezpl.media_type" "continuous"
! U1 "ezpl.print_mode" "tear off"
【问题讨论】:
标签:
android
image
printing
zebra-printers
zpl
【解决方案1】:
有使用 ZEBRA iMZ320 打印 UIImage 的完整示例(Objective-C)。我认为,您可以使用相同的打印命令并在 Java 或 Kotlin 中准备适当的代码:
UIImage *image = ...; //printing image; default wight should be ~572
id<ZebraPrinterConnection, NSObject> connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
if (![connection open]) {
NSLog(@"Printer Error! Please check the printer and try it again.");
return;
}
NSError *error = nil;
id<ZebraPrinter, NSObject> printer = [ZebraPrinterFactory getInstance:connection error:&error];
PrinterStatus *status = [printer getCurrentStatus:&error];
if (status == nil) {
NSLog(@"Error: %@", [error localizedDescription]);
return;
} else if (!status.isReadyToPrint) {
NSLog(@"The printor is not ready to print");
return;
}
CGSize imageSize = image.size;
//Send configuration command with setting "media_type" = "continuous" and "printing height" = "imageSize.height"
for (NSString *cmd in @[@"! U1 setvar \"ezpl.media_type\" \"continuous\"\r\n",
[NSString stringWithFormat:@"! U1 setvar \"zpl.label_length\" \"%d\"\r\n", (int)imageSize.height]]) {
if (![[printer getToolsUtil] sendCommand:cmd error:&error]) {
NSLog(error == nil ? @"Printer Error! Please check the printer and try it again." : [error localizedDescription]));
return;
}
}
[NSThread sleepForTimeInterval:1];
if ([[printer getGraphicsUtil] printImage:[image CGImage] atX:0 atY:0 withWidth:-1 withHeight:-1 andIsInsideFormat:false error:&error]) {
status = [printer getCurrentStatus:&error];
int i = 0;
while (!status.isReadyToPrint || i > 30) {
[NSThread sleepForTimeInterval:1];
status = [printer getCurrentStatus:&error];
i++;
}
[NSThread sleepForTimeInterval:1];
NSLog(@"Prining should be success");
} else {
NSLog(error == nil ? @"Printer Error! Please check the printer and try it again." : [error localizedDescription]));
}
for (NSString *cmd in @[[NSString stringWithFormat:@"! U1 setvar \"zpl.label_length\" \"%d\"\r\n", 50],
@"PRINT\r\n"]) {
[[printer getToolsUtil] sendCommand:cmd error:nil];
}
[connection close];