1

I need to embed a web inside a MAC executable, so that the html is inside the executable (and not loaded from an external server). It should also be possible to print the contents of the webview.

I have tried with Xcode and Swift, but when printing the webview it looks blank, there are lots of entries in Stack Overflow and seems to be no solution for this in swift.

I have also tried Xojo.com, but the contents are outside the executable visible to the user and must be hidden inside.

Any guidance?

CODE:

import Cocoa
import WebKit


class ViewController: NSViewController {

    @IBOutlet weak var WEBVW: WKWebView!
    
    override func viewDidLoad() {
  
        super.viewDidLoad()
        
          if let url = Bundle.main.url ( forResource: "index"
                                         , withExtension: "html"
                                        , subdirectory: "www")
                {
                let path = url.deletingLastPathComponent();
                self.WEBVW.loadFileURL ( url
                                         , allowingReadAccessTo: path);
            
                WEBVW.printView(self)
          }

    }
}

IMAGE: Program running and printing: https://postimg.cc/Lqsddv1T

Many thanks

Willeke
  • 14,578
  • 4
  • 19
  • 47
Manuel D
  • 11
  • 3
  • "when printing the webview it looks blank" How!? We don't see it. – El Tomato Apr 27 '21 at 10:27
  • What about https://stackoverflow.com/questions/37048759/swift-display-html-data-in-a-label-or-textview – Joakim Danielson Apr 27 '21 at 10:30
  • I have added the code and a screenshot of what happens when trying to print. As you can see it appears blank page. – Manuel D Apr 27 '21 at 11:33
  • Does this answer your question? [Printing contents of WKWebView (OS X)](https://stackoverflow.com/questions/29236929/printing-contents-of-wkwebview-os-x) – Willeke Apr 27 '21 at 14:34
  • Or this? [How does one Print all WKWebView On AND Offscreen content OSX and iOS](https://stackoverflow.com/questions/33319295/how-does-one-print-all-wkwebview-on-and-offscreen-content-osx-and-ios) – Willeke Apr 27 '21 at 14:36
  • Thank you, I had seen that solution. It's objective-c and my project is in swift. I'm a newbie programming on the MAC platform. Could someone give me an example on how to use that code in a swift project? – Manuel D Apr 27 '21 at 18:56

0 Answers0