我在我的应用程序中打印不同的图像。问题是打印机总是在整个页面中打印图像。如果图像尺寸非常小,则打印机会打印整个页面,并且看起来非常糟糕。我使用以下代码打印图像:
NSData *dataFromPath = UIImageJPEGRepresentation(croppedImage, 1.0);
if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {
printController.delegate = self;
UIPrintFormatter *my=[[UIPrintFormatter alloc]init];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"print image";
printInfo.duplex = UIPrintInfoDuplexNone;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
printController.printingItem = dataFromPath;
[printController presentFromRect:_btn_ShareAction.frame inView:_btn_ShareAction.superview animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
}
}];
}发布于 2015-01-31 06:58:56
您可以使用printPageRenderer属性并实现自己的打印逻辑,而不是使用printingItem,这将使您能够按照所需的确切位置和大小进行打印。
https://stackoverflow.com/questions/24692491
复制相似问题