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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…