【问题标题】:How can I show rtf file with wmf images in ios如何在 ios 中显示带有 wmf 图像的 rtf 文件
【发布时间】:2015-12-02 16:41:18
【问题描述】:

我有一个.rtf 文件。它包含带有Windows Metafile Format(wmf) 的图像。我想在iOS 应用程序中显示这个文件。我尝试使用NSAttributedStringUIWebView 显示它,但没有显示图像。 如何在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]];

EDIT2

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

RTFD 文件创建一个包含 TXT.rtf 和文件中图像的包。在TXT.rtf 文件中,图像作为参考给出,单独存储在 RTFD 中。如下:

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

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

【问题讨论】:

    标签: ios image-processing rtf wmf


    【解决方案1】:

    尝试转换为rtfd而不是rtf

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-06
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多