2

I have a .rtf file. It contains images with Windows Metafile Format(wmf). I want to show this file in iOS app. I tried showing it using NSAttributedString and in UIWebView but images are not shown. How can I show it on iOS device ?

EDIT

For NSAttributedString:

var urlpath = NSBundle.mainBundle().pathForResource("txtFile", ofType: "rtf")
var url:NSURL = NSURL.fileURLWithPath(urlpath!)!
if let attributedText = NSAttributedString(fileURL: url, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil, error: nil) {
    textView.attributedText = attributedText
}

For UIWebView:

NSString *path = [[NSBundle mainBundle] pathForResource:@"txtFile" ofType:@"rtf"];
NSURL *url = [NSURL URLWithString:path];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];

EDIT2

I tried converting .rtf file into .rtfd file format.

RTFD file creates a bundle with TXT.rtf and images in files. In TXT.rtf file, images are given as references which are stored separately in RTFD. Like following :

{{\NeXTGraphic img1.png \width40 \height20}¬}

I converted the file into RTFD but issue comes when file contains .wmf images. Images with .wmf file format are not getting converted.

sagar.musale
  • 585
  • 1
  • 7
  • 19

1 Answers1

0

Try converting to rtfd insead of rtf

Rich Text Format Directory, also known as RTFD (due to its extension .rtfd), or Rich Text Format with Attachments

var urlpath = NSBundle.mainBundle().pathForResource("txtFile", ofType: "rtfd")
var url:NSURL = NSURL.fileURLWithPath(urlpath!)!
if let attributedText = NSAttributedString(fileURL: url, options: [NSDocumentTypeDocumentAttribute:NSRTFDTextDocumentType], documentAttributes: nil, error: nil) {
     textView.attributedText = attributedText
}
sagar.musale
  • 585
  • 1
  • 7
  • 19
MangoCode
  • 28
  • 7