ios - 在 Objective c 中解析 RTF

标签 ios objective-c rtf

我想在 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/

相关文章:

ios - 动画 subview AutoLayout 约束更改

objective-c - 来自 UITableViewController 的 NSRangeException

objective-c - 带有字体名称和粗体的 UITextView 格式

java - 在 JEditorPane 中动态添加 rtf 文件的超链接

ios - presentViewController 后导航栏不显示

iphone - 如何绘制心率图表?

iOS 从 UIWebView 移除阴影

ios - 在没有 CATransaction begin&commit 的情况下禁用隐式动画

.net - 如何分割 RTF 文件

win-universal-app - UWP/Windows 10 Mobile 的文档支持(rtf、doc、docx)