我一直在玩 iOS 4.2 UIWebView + AirPrint。然而,问题是从 UIWebView 获取 viewPrintFormatter 我能够打印 PDF 和图像,但不能打印 DOC、DOCX、PPT、PPTX 等。这些文件在 UIWebView 中正确显示,但 Airprint 将打印空白页.
这是我的代码:
[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];