How to print the content of a WKWebView
using printOperation(with:)?
First try
let info = NSPrintInfo.shared
let operation = printOperation(with: info)
operation.run()
But I get a crash with the message:
[Printing] ERROR: The NSPrintOperation view's frame was not initialized properly before knowsPageRange: returned. (WKPrintingView)
But the view
property on NSPrintOperation
is read only.
Second try
if instead I try to run the operation modally and disable the print panel like this:
operation.showsPrintPanel = false
guard let window = webView.window else { return }
operation.runModal(for: window, delegate: nil, didRun: nil, contextInfo: nil)
I get an alert with the message:
To print this file, you must set up a printer.
And it is true, I haven't setup a printer, but what about printing (i.e. saving) to PDF?