我想在 Objective c 中解析 RTF 文件。可以解析吗?如果可能,那么我如何将它用于 IOS。我想要所有的文本和格式。 为此,我尝试了很多方法来获取文本和格式,我使用了 UIWEBVIEW,但它不返回任何文本字符串
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"];
这里 html 返回 nil 值。 谢谢
最佳答案
好吧,这个问题很老了,但如果有人偶然发现这个问题:
html
为 nil,因为 webView
未完成加载。在 UIWebViewDelegate
中获取 html:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"];
NSLog(@"Html: %@",html);
}
您将获得所需的 html。
关于ios - 在 Objective c 中解析 RTF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17148146/