Reputation: 813
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
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