2

我有一个.rtf文件。它包含带有Windows Metafile Format(wmf). 我想在iOS应用程序中显示这个文件。我尝试使用NSAttributedStringand in显示它,UIWebView但未显示图像。如何在iOS设备上显示它?

编辑

对于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
}

对于UIWebView

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

编辑2

我尝试将.rtf文件转换为.rtfd文件格式。

TXT.rtfRTFD 文件在文件中创建包含和图像的捆绑包。在TXT.rtf文件中,图像作为参考给出,分别存储在 RTFD 中。如下所示:

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

我将文件转换为 RTFD,但是当文件包含.wmf图像时会出现问题。.wmf文件格式的图像没有得到转换。

4

1 回答 1

0

尝试转换为rtfdinsead ofrtf

Rich Text Format Directory,也称为RTFD(由于其扩展名为 .rtfd),或带有附件的富文本格式

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
}
于 2015-10-05T22:30:53.177 回答