【问题标题】:How extract image from DOC file without using of Microsoft.Office.Interop.Word如何在不使用 Microsoft.Office.Interop.Word 的情况下从 DOC 文件中提取图像
【发布时间】:2017-07-26 08:58:00
【问题描述】:

我正在尝试在不使用 Microsoft.Office.Interop.Word 的情况下从 *.doc 文件中提取图像。我找到了像 FreeSpire.Doc 这样的库,但似乎免费版本的库无法提取图像。有人可以帮我解决这个问题吗?

Attached *.doc file with the image I need 谢谢你

【问题讨论】:

  • 你是绑定.doc-documents 还是可以使用.docx
  • 是的,我的源文档类型是 *.doc。

标签: c# doc


【解决方案1】:

我发现的唯一可以从 .doc 文档中提取图像的库是 Aspose。他们的文档中有一个example,您可以如何导出图像。

【讨论】:

  • Shape 命名空间:Aspose.Words.Drawing 必须在 VS 中手动添加
【解决方案2】:

我最终得到了这个解决方案。我找到了一个名为 GemBox.Document 的库。不幸的是,该库仅对包含最多 20 段的文档免费。所以我不得不删除多余的段落,然后我使用这段代码来获取文档中的第一张图片。

        public void CreateSubnestImageFromNestingReport(string picturePath,string  docPath)
    {
        var fileDir = Path.GetDirectoryName(picturePath);
        Directory.CreateDirectory(fileDir);

        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
        var document = DocumentModel.Load(docPath, LoadOptions.DocDefault);
        var pict = document.GetChildElements(true).Single(el => el.ElementType == ElementType.Picture) as Picture;
        File.WriteAllBytes(picturePath, pict.PictureStream.ToArray());            
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多