【发布时间】:2019-11-04 20:41:11
【问题描述】:
我使用 iZM320 打印机打印这样的收据:
https://gyazo.com/67aa41cf2f8d392f516494f64cde4d01
我使用代码:
1) 打印字符串(有效)
-(BOOL)printReportAsOneJobUsingNSString:(id<NSObject,ZebraPrinter>)printer withString:(NSMutableString*)fullLabel {
NSError *error = nil;
long blockSize = 256;
long totalSize = fullLabel.length;
long bytesRemaining = totalSize;
while (bytesRemaining > 0) {
long bytesToSend = MIN(blockSize, bytesRemaining);
NSRange range = NSMakeRange(0, bytesToSend);
NSString *partialLabel = [fullLabel substringWithRange:range];
[[printer getToolsUtil] sendCommand:partialLabel error:&error];
bytesRemaining -= bytesToSend;
[fullLabel deleteCharactersInRange:range];
}
return (error == nil);
}
2) 打印图片
if (_printImage) {
id<GraphicsUtil, NSObject> graphicsUtil = [printer getGraphicsUtil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError *error = nil;
[graphicsUtil printImage:[_printImage CGImage] atX:_posX atY:_posYwithWidth:_printImage.size.width withHeight:_printImage.size.height andIsInsideFormat:NOerror:&error];
});
}
但我不知道如何结合这些功能来打印我想要的收据。 请你帮帮我。
非常感谢!!
【问题讨论】:
标签: ios objective-c zebra-printers