IOS 4.2 - Print DOC, PPT, XLS, etc. with Apple AirPrint?

I played with iOS 4.2 UIWebView + AirPrint. The problem is that getting viewPrintFormatter from UIWebView I can print PDF and images, but not DOC, DOCX, PPT, PPTX, etc. These files display correctly in UIWebView, but Airprint prints 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];
+3
source share
2 answers

I found how to fix this, for some reason, if I do not use the mime type, it works. I just saved the file to local storage and used a different upload method for the web view, which downloads content based only on the url. Hope this helps ...

+1
source

, , . loadRequest:

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

Source: https://habr.com/ru/post/1780717/


All Articles