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

3
  • 1
    here is an answer to a different question that may be of use to you. The idea is to use UIWebView. Commented Feb 29, 2012 at 14:57
  • 1
    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? Commented Feb 29, 2012 at 14:59
  • Thanks very much for the comments and answers. Commented Mar 12, 2012 at 3:16

2 Answers 2

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.

2
  • Thank you very much. I'm going to give this a go. Commented Mar 12, 2012 at 3:16
  • 1
    In my case, I had to change @".rtf" to @"rtf" otherwise URLForResource:withExtension: would return nil.
    – Mike
    Commented Jan 24, 2013 at 2:35
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)
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.