I am trying to print the contents of a WkWebView
, but when the print panel appears the print preview is empty.
Here is the code:
- (voi
You can print the contents of WKWebView
with viewPrintFormatter
.
Here is the sample code:
if ([UIPrintInteractionController isPrintingAvailable])
{
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = @"Print";
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = self.webView.viewPrintFormatter;
[pic presentFromBarButtonItem:barButton animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
if(error)
NSLog(@"handle error here");
else
NSLog(@"success");
}];
}