I need to print some outline art for kids to color. It’s just the image, no UI, no other content.
Does anyone know how to print from a WKWebView? I have a button in my app that calls upon a window.print() function that works on desktop, but not on iOS.
How can I bring the window picker on iOS to select the Print option? From what I’ve read, there’s no easy way. Would it just be easier to open a browser with the image I need to print and print from Safari instead?
THank you for this. But I pasted this code on my WebViewController and got several errors. I guess it needs a function before, but not sure what that is.
Ah yes, I’m a designer, so no knowledge of swift whatsoever. Previously I was able to compare your Xcode files with mine and figure out which code to copy/paste to make the external URL work.
With the print function, though, because I already had a
let messageName = “openStore”
for the URL function, I used the same messageName for printing, but it didn’t work.
I’m attaching my Xcode with your Hype file. Perhaps you can take a look and see what’s wrong? I changed your button so it’s now
window.webkit.messageHandlers.openStore.postMessage(‘print’); // post
It is because your have two if conditions looking for the same thing.
You really need to get some basics under your belt in JS and then some of swift may make sense to you since a lot of the structure in the very basic syntax is similar.
In you example
change this lines.
//-- declare a message name to use later
let messageName = "openStore"
to
//-- declare a message name to use later
let openStore = "openStore"
let printPage = "print"
change the lines
//MARK: - PRINT
if message.name == "openStore"{
let webviewPrint = webView.viewPrintFormatter()
to
//MARK: - PRINT
if message.name == printPage {
let webviewPrint = webView.viewPrintFormatter()