Swift Mac OS:当我尝试打印webView(WKWebView)时打印的空白页

Swift Mac OS:当我尝试打印webView(WKWebView)时打印的空白页,swift,macos,printing,webview,wkwebview,Swift,Macos,Printing,Webview,Wkwebview,我使用以下代码使webView呈现给定的HTML字符串: let filePath = Bundle.main.path(forResource: "my file name", ofType: "html") let htmlStr = try! NSString.init(contentsOfFile: filePath!, encoding: String.Encoding.utf8.rawValue) webView.loadHTMLString(htmlStr as String, b

我使用以下代码使webView呈现给定的HTML字符串:

let filePath = Bundle.main.path(forResource: "my file name", ofType: "html")
let htmlStr = try! NSString.init(contentsOfFile: filePath!, encoding: String.Encoding.utf8.rawValue)
webView.loadHTMLString(htmlStr as String, baseURL: nil)
webView
正确显示HTML,但当我尝试打印它时,打印面板显示空白页,我使用了以下方法:

webView.printView(nil)
我也试过这个:

NSPrintOperation(view: webView).run()

所有显示的打印面板均为空白页!有什么帮助吗

重复:在WKWebView中的new Swift no more(mainFrame)属性中,因此如何将其转换为新的Swift:NSPrintOperation(视图:webView.mainFrame.frameView.documentView)。runOperation()阅读文档。文档中说:从iOS 8.0和OS X 10.10开始,使用WKWebView向应用程序添加web内容。请勿在WKWebView中使用UIWebView或WebView没有webFrame。。文档中也没有说明如何打印webView。。见: