Display pdf inside swift ui

Hi! I'm creating an app for iOS and I want just to display a pdf from an external url with the width of 300 and height of 500.

I tried with UiWebView but it is no longer supported.

import SwiftUI



let webView = UIWebView(frame: CGRect(x: 10, y: 10, width: 500, height: 300))



let targetURL = NSURL(string: "https://www.example.com/document.pdf")! 

let request = NSURLRequest(URL: targetURL)

webView.loadRequest(request)



struct StundenplanCard: View {

    var body: some View {

        VStack(spacing: 20) {

            Text("Gimnazium")

             // here should be displayed the pdf
        }

    }

}



struct StundenplanCard_Previews: PreviewProvider {

    static var previews: some View {

        StundenplanCard().previewLayout(.fixed(width: 320, height: 640))

    }

}
Answered by Claude31 in 687054022

Did you try using WKWebView instead ?

See details here: h t t p s : / / gist.github.com/joshbetz/2ff5922203240d4685d5bdb5ada79105

Accepted Answer

Did you try using WKWebView instead ?

See details here: h t t p s : / / gist.github.com/joshbetz/2ff5922203240d4685d5bdb5ada79105

Display pdf inside swift ui
 
 
Q