试试这个代码可能对你有帮助
- (IBAction)btnPrintTapped:(id)sender {
NSData *imageData = UIImagePNGRepresentation(self.imgV.image);
[self printItem:imageData];
}
#pragma mark - Printing
-(void)printItem :(NSData*)data {
printController = [UIPrintInteractionController sharedPrintController];
if(printController && [UIPrintInteractionController canPrintData:data]) {
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [NSString stringWithFormat:@""];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
printController.printingItem = data;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
//NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[printController presentFromBarButtonItem:self.item animated:YES completionHandler:completionHandler];
}
}
- (BOOL)presentFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion {
return YES;
}
- (BOOL)presentFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated completionHandler:(UIPrintInteractionCompletionHandler)completion {
return YES;
}