Search code examples
c#doc

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


I'm trying to extract image from *.doc file without using of Microsoft.Office.Interop.Word. I found library like FreeSpire.Doc, but It seems the free version of library isn't able to extract images. Can someone help me with this problem?

[Attached *.doc file with the image I need][1] [1]: https://mega.nz/#!5nITyQzT!aesEA0akirlpKSEEDceNDjifOAFKlNZSmgTwfhFm36M

Thank you


Solution

  • I ended up with this solution. I found a library named GemBox.Document. Unluckily this library is free only for documents containing up to 20 paragraphs. So I had to remove extra paragraphs and then I used this code to get first picture in document.

            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());            
        }