iOS 4.2 - 使用 Apple AirPrint 打印 DOC、PPT、XLS 等?

发布于 2024-10-08 03:29:34 字数 1050 浏览 2 评论 0原文

我一直在玩 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-10-15 03:29:34

我找到了如何修复它,出于某种原因,如果我不使用它可以工作的 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...

ま昔日黯然 2024-10-15 03:29:34

谢谢,我按照你的提示操作,现在可以了。使用 loadRequest 代替:

[internalWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];

Thanks, I follow your hint and it work now. Using loadRequest instead:

[internalWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文