问题
I've been playing with iOS 4.2 UIWebView + AirPrint. The problem, however, is that getting the viewPrintFormatter from the UIWebView I'm able to print PDF and images, but not DOC, DOCX, PPT, PPTX, etc. Those files are displayed properly in the UIWebView, but Airprint will print blank pages.
Here is my code:
[internalWebView loadData:[[printContent objectAtIndex:0] data] MIMEType:mimeType textEncodingName:nil baseURL:nil];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
//pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [[printContent objectAtIndex:0] fileName];
pic.printInfo = printInfo;
pic.printFormatter = [internalWebView viewPrintFormatter];
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
回答1:
I found how to fix it, for some reason if I don't use the mime type it works. I just saved the file to the local storage and used the other load method for the webview that loads the content based only on an URL. Hope it helps...
回答2:
Thanks, I follow your hint and it work now. Using loadRequest instead:
[internalWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
来源:https://stackoverflow.com/questions/4463223/ios-4-2-printing-doc-ppt-xls-etc-with-apple-airprint