WKWebView does not render PDF pages in AirPrint preview.

Originator:stkhapugin
Number:rdar://23556241 Date Originated:16-11-2015
Status:Open Resolved:
Product:iOS Product Version:9.1
Classification: Reproducible:
 
Summary:
When one attempts to AirPrint a PDF open in WKWebView using [WKWebView viewPrintFormatter], the previews and the printed output are blank. 
Note that Safari on iOS prints normally.

Steps to Reproduce:
Unzip attached project, build & run. A pdf document will be loaded, and once it's loaded, the print dialog will open.

Expected Results:
Preview in print dialog shows a small PDF preview. PDF prints normally.

Actual Results:
Previews in print dialog shows a blank page. Printed page is blank.

Version:
iOS 9.1

Configuration:
iPhone 6s, also simulator

Attachments:
'TestPrint.zip' was successfully uploaded. Since attachments are not available on openradar, you need to do the following:
1. create a "Single View" project
2. Replace ViewController.m with the following:
#import "ViewController.h"

#import <MobileCoreServices/MobileCoreServices.h>
#import <WebKit/WebKit.h>

@interface ViewController () <WKNavigationDelegate>
@property(nonatomic, weak) WKWebView* webView;
@end

@implementation ViewController

- (void) viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  
  NSString* pdfLink = @"http://www.cbu.edu.zm/downloads/pdf-sample.pdf";
  NSURL* pdfURL = [NSURL URLWithString:pdfLink];
  
  WKWebView* webView = [[WKWebView alloc] init];
  [self.view addSubview:webView];
  webView.frame = self.view.bounds;
  webView.navigationDelegate = self;
  [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
  self.webView = webView;
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
  // Start printing
  UIPrintInfo* printInfo = [UIPrintInfo printInfo];
  printInfo.outputType = UIPrintInfoOutputGrayscale;
  printInfo.jobName = @"PDF Sample";

  UIPrintInteractionController* printController = [UIPrintInteractionController sharedPrintController];
  [printController setPrintInfo:printInfo];
  [printController setPrintFormatter:[self.webView viewPrintFormatter]];
  [printController presentAnimated:YES completionHandler:nil];
}

@end

3. Add WebKit and MobileCoreServices frameworks to linked frameworks section.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!