4

For a project I need to display the contents of a RTF file on an iPad. After some searches I found that you can load the RTF file in an UIWebView. However when I do this, the content of the file shows up, but its missing table borders, and images. Bold / Italic / Underlined text works fine.

The code I use to display the file:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"A" withExtension:@".rtf"];

NSLog(@"URL: %@", url);

NSURLRequest *req = [NSURLRequest requestWithURL:url];

[_webView loadRequest:req];

The RTF file:

https://dl.dropbox.com/u/4966217/A.rtf

How can I display the images and table borders in my app?

Geert
  • 1,217
  • 8
  • 20

2 Answers2

0

If you want only to show rtf file then you can also use QLPreviewController. It supports many file formats for preview.

Here is the documentation link for QLPreviewController: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/QLPreviewController_Class/Reference/Reference.html

And here is sample code : http://developer.apple.com/library/ios/#samplecode/DocInteraction/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010052

Yuvrajsinh
  • 4,536
  • 1
  • 18
  • 32
  • It does indeed show the RTF file, but it doesn't show table borders and images – Geert Dec 05 '12 at 07:58
  • My idea was, if your strictly need is not to show RTF in UIWebView then you can show it in QLPreviewController that shows the file as it is. – Yuvrajsinh Dec 05 '12 at 09:48
  • My problem was not the UIWebView, it was the content missing of the RTF file – Geert Dec 05 '12 at 10:02
  • As i have checked in QLPreviewController also, it is not showing table in RTF file. If possible then create HTML for your RTF content. – Yuvrajsinh Dec 05 '12 at 10:21
  • It isn't, since there is a database with about 15K RTF files in it – Geert Dec 05 '12 at 10:37
-2

Try this code

NSString *filePath = [[NSBundle mainBundle] pathForAuxiliaryExecutable:@"A.rtf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:fileURL];
[_webView loadRequest:requestObj];

to convert it to html

http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/

http://kiefermat.com/2011/09/30/using-uiwebview-for-displaying-rich-text/

Sharanya K M
  • 1,805
  • 4
  • 23
  • 44
  • That does the same thing as it does now, it opens the file, and it shows the table without borders, and doesn't show the image. – Geert Oct 05 '12 at 07:13