Shinning River
Shinning River

Reputation: 813

Parse RTF in Objective c

I want to parse RTF file in Objective c.Is its possible to parse it? if is possible then how can I use it into IOS.I want all the text and formatting. I have tried in so many way to get text and formatting for this purpose I have used UIWEBVIEW but its not return any text string

NSURL *imgPath = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"rtf"];
NSData *data = [NSData dataWithContentsOfURL:imgPath];
[webView loadData:data MIMEType:@"text/rtf" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"/"]];
 NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];

Here html return nil value. Thanks

Upvotes: 2

Views: 843

Answers (1)

SHN
SHN

Reputation: 795

Ok, this question is very old but in case someone stumbles across this problem:

The html is nil as the webView is not finished loading. Fetch the html in the UIWebViewDelegate:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];

    NSLog(@"Html: %@",html);

}

You will get the desired html.

Upvotes: 1

Related Questions