如何在不使用 Microsoft.Office.Interop.Word 的情况下从 DOC 文件中提取图像

How extract image from DOC file without using of Microsoft.Office.Interop.Word

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

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

我发现的唯一可以从 .doc 文档中提取图像的库是 Aspose. There is an example 在其文档中如何导出图像。

我最终得到了这个解决方案。我找到了一个名为 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());            
    }