Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Objective C: Display RTF document

Tags:

ios

rtf

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

like image 486
Jason TEPOORTEN Avatar asked Feb 29 '12 14:02

Jason TEPOORTEN


2 Answers

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.

like image 88
pmf Avatar answered Nov 15 '22 17:11

pmf


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)
}
like image 43
xdeleon Avatar answered Nov 15 '22 17:11

xdeleon