我一直在玩 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];
最佳答案
我找到了如何修复它,出于某种原因,如果我不使用它可以工作的 mime 类型。我只是将文件保存到本地存储,并使用 webview 的其他加载方法,仅根据 URL 加载内容。希望对您有帮助...
关于iphone - iOS 4.2 - 使用 Apple AirPrint 打印 DOC、PPT、XLS 等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4463223/