WKWebView: how to print webpage?

I have an app that downloads some html to the app's documents folder and then I'm displaying that html in WKWebView:

class ViewController: UIViewController {

@IBOutlet weak var wkWebView: WKWebView!
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

override func viewDidLoad() {
    super.viewDidLoad()
    let destinationURL = self.documentsURL.appendingPathComponent("web", isDirectory: true)
    let indexURL = destinationURL.appendingPathComponent("index.html")
    wkWebView.loadFileURL(indexURL, allowingReadAccessTo: destinationURL)
}
}

This is the content of that html:

<!DOCTYPE html>
<html>
<body>
<h2>Sample webpage</h2>
<p>Click the button to print the current page.</p>
<a href="javascript:print()">
    <img src="https://image.flaticon.com/icons/png/128/446/446991.png" alt="print">
</a>
</body>
</html>

When user clicks the anchor I want to pull up this printing modal. There is very little info out there how to achieve this that seems outdated and so far none of it worked and I am stuck. What's the best way to implement this in 2021?



from Recent Questions - Stack Overflow https://ift.tt/2TG1xkF
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation