【问题标题】:WKWebView - Open Print DialogWKWebView - 打开打印对话框
【发布时间】:2016-12-21 09:57:24
【问题描述】:

我在旧的 Cocoa 项目中使用普通的 WebView 组件,并且可以覆盖

-(void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView

在必要时显示打印对话框。

如何使用 WKWebView 做同样的事情?我在文档中找不到任何关于打印的方法。

【问题讨论】:

    标签: swift cocoa wkwebview


    【解决方案1】:

    我有以下方法在 WKWebView 上使用 Swift 进行 AirPrint(例如显示打印对话框)。它将弹出打印对话框,并在需要时跨多个页面正确格式化文本。我从应用程序上的“打印”按钮调用 printPage。

    webViewX 是一个 WKWebView,在类的其他地方定义:

    var webViewX: WKWebView!
    //do all the work for populating the webViewX somewhere else in the class
    
    @objc func printPage(sender: AnyObject)
    {
        let pInfo :UIPrintInfo =  UIPrintInfo.printInfo()
        pInfo.outputType = UIPrintInfo.OutputType.general
        pInfo.jobName = self.title //page title defined elsewhere
        pInfo.orientation = UIPrintInfo.Orientation.portrait
    
        let printController = UIPrintInteractionController.shared
        printController.printInfo = pInfo
        printController.printFormatter = webViewX.viewPrintFormatter()
        printController.present(animated: true, completionHandler: nil)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 2015-07-05
      • 2013-06-15
      • 2013-04-05
      相关资源
      最近更新 更多