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

Jason TEPOORTEN
  • 431
  • 5
  • 10
  • 1
    [here](http://stackoverflow.com/a/4779065/335858) is an answer to a different question that may be of use to you. The idea is to use `UIWebView`. – Sergey Kalinichenko Feb 29 '12 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? – Philip Sheard Feb 29 '12 at 14:59
  • Thanks very much for the comments and answers. – Jason TEPOORTEN Mar 12 '12 at 03:16

2 Answers2

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.

Sam B
  • 27,273
  • 15
  • 84
  • 121
pmf
  • 577
  • 4
  • 14
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)
}
xdeleon
  • 769
  • 8
  • 20