开发者

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

开发者 https://www.devze.com 2023-01-31 03:50 出处:网络
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, e

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 *) =
^(UIPrintInteractionControlle开发者_开发知识库r *printController, BOOL completed, NSError *error) {
 if (!completed && error) {
  NSLog(@"Printing could not complete because of error: %@", error);
 }
};

[pic presentAnimated:YES completionHandler:completionHandler];


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...


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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号