iOS Objective C: Display RTF document
Asked Answered
B

2

11

I want to show a RTF document in a view. This document will be developed in Microsoft Word and will contains images.

What is the best way to do this using standard routines provided?

I would really like sample code to load a RTF document from the bundle. Kind Regards, Jason

Barthold answered 29/2, 2012 at 14:50 Comment(3)
here is an answer to a different question that may be of use to you. The idea is to use UIWebView.Prowl
That is a real clash of cultures, because RTF is a proprietary Microsoft standard, and a very old one at that. But why is a Word application saving a document in RTF format? Did someone think it was a good idea?Studer
Thanks very much for the comments and answers.Barthold
M
20

UIWebView opens .rtf documents. Try something like

NSURL *rtfUrl = [[NSBundle mainBundle] URLForResource:@"MyFileName" withExtension:@"rtf"];
NSURLRequest *request = [NSURLRequest requestWithURL:rtfUrl];
[_webview loadRequest:request];

See the documentation for UIWebView file types.

Moton answered 29/2, 2012 at 17:11 Comment(2)
Thank you very much. I'm going to give this a go.Barthold
In my case, I had to change @".rtf" to @"rtf" otherwise URLForResource:withExtension: would return nil.Eclampsia
W
2

If you need to do this in Swift instead of Obective-C here's a Swift equivalent of @pmf's answer as a function you can call.

func loadRTFDocument() {
    let urlPath =  NSBundle.mainBundle().pathForResource("TermsOfUse", ofType: "rtf")
    let url = NSURL.fileURLWithPath(urlPath!)
    let request = NSURLRequest.init(URL: url)
    self.webView.loadRequest(request)
}
Whitby answered 30/12, 2015 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.