Printing contents of WKWebView (OS X)

前端 未结 3 1456
后悔当初
后悔当初 2020-12-17 16:24

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         


        
3条回答
  •  执笔经年
    2020-12-17 16:56

    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");
        }];
    }
    

提交回复
热议问题