iOS 4.2 - Printing DOC, PPT, XLS, etc. with Apple AirPrint?

走远了吗. 提交于 2019-12-03 06:25:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!