1

I want to load a RTFD file (rtf with images) in a WebView. So I created a file in TextEdit with a text and one image, and saved as doc.rtfd

[File created with TextEdit1

In order load the file on SwiftUI I tried the following code:

import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
    
    func makeUIView(context: Context) -> WKWebView {
        return WKWebView()
    }
    
    func updateUIView(_ webView: WKWebView, context: Context) {
        
        let request = URLRequest(url: getURL()! )
        webView.load(request)
    }
    
    public func getURL() -> URL? {
        guard let url: URL = Bundle.main.url(forResource: "doc.rtfd.zip", withExtension: nil) else { return nil }
        return url
    }
}

And then:

struct ExampleWebView: View {
    var body: some View {
        VStack {
                WebView( )
                
                    .ignoresSafeArea()
                    .navigationTitle("RTF View")
                    .navigationBarTitleDisplayMode(.inline)
           
            Spacer()
        }
    }  
}

But as a result, only the text is displayed correctly. For the image only the name (M2.png) is present:

SwiftUI screen

What I am missing?

1
  • Can you load the RTFD bundle and write its content to a local file to compare it with the original? Commented Feb 11, 2024 at 11:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.