Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

ios - How do I convert a Word doc to HTML and load it as a local file in WKWebView?

The Word doc has been converted to HTML using: https://word2cleanhtml.com/cleanit

Here is a sample of the HTML generated (perhaps the problem is here because I know next to nothing about HTML):

<p dir="ltr">
    TERMS AND CONDITIONS
</p>
<p dir="ltr">
    Last updated: 2020-06-01
</p>
<p dir="ltr">
    1. Introduction
</p>
<p dir="ltr">
    Welcome to MyCompany (“Company”, “we”, “our”, “us”)!
</p>
<p dir="ltr">
    These Terms of Service (“Terms”, “Terms of Service”) govern your use of our
    mobile application (individually herein after referred also as “Service”)
    operated by MyCompany.
</p>

And then I load this into a WKWebView in a view controller like this:

import WebKit

class Terms: UIViewController {
    
    let termsWebView: WKWebView = {
        let webview = WKWebView()
        webview.backgroundColor = .white
        return webview
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view = termsWebView
        loadTermsHTML()
    }
    
    func loadTermsHTML() {
        
        guard let path = Bundle.main.path(forResource: "tnc", ofType: "html") else { return }
        let url = URL(fileURLWithPath: path)
        if let data = try? Data(contentsOf: url) {
            let termsString = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
            termsWebView.loadHTMLString(termsString! as String, baseURL: nil)
        }
    }
}

The problem is that while the HTML is loaded, it's not rendering based on the formatting. I just see the exact same content with the markup language in the HTML file that I added into the project directory.

question from:https://stackoverflow.com/questions/65861468/how-do-i-convert-a-word-doc-to-html-and-load-it-as-a-local-file-in-wkwebview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...