iOS 4.2 - 使用 Apple AirPrint 打印 DOC、PPT、XLS 等?
我一直在玩 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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了如何修复它,出于某种原因,如果我不使用它可以工作的 mime 类型。我只是将文件保存到本地存储,并使用 webview 的其他加载方法,仅根据 URL 加载内容。希望它有帮助...
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...
谢谢,我按照你的提示操作,现在可以了。使用 loadRequest 代替:
Thanks, I follow your hint and it work now. Using loadRequest instead: