Extract images from word document

I am trying to extract images from word documents. I am using code based on examples provided in the documentation for doing this task. The example code is as follows:

public void extractImagesToFiles() throws Exception
{
Document doc = new Document(getMyDir() + “Image.SampleImages.doc”);
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, <span class="code-keyword">true</span>);
<span class="code-object">int</span> imageIndex = 0;
<span class="code-keyword">for</span> (Shape shape : (Iterable<Shape>) shapes)
{
    <span class="code-keyword">if</span> (shape.hasImage())
    {
        <span class="code-object">String</span> imageFileName = java.text.MessageFormat.format(
                <span class="code-quote">"Image.ExportImages.{0} Out{1}"</span>, imageIndex, FileFormatUtil.imageTypeToExtension(shape.getImageData().getImageType()));
        shape.getImageData().save(getMyDir() + imageFileName);
        imageIndex++;
    }
}

}


The problem is that the above code does not find all the images in the file.
The attached file contains header/footer images, as well as the seal image,
and none are reported using the method outlined above. Can you assist?

Hi Brian,

Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v15.4.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v15.4.0 and let us know how it goes on your side. I hope, this will help.

Ahh. It has to do with the merging of DrawingML and Shape class which took place in 15.2. I’ll look into upgrading, but we have deployed code out there using 14.10, so I may need to work-around.

Hi Brian,

Thanks for your inquiry. We removed the DrawingML from the Aspose.Words API. Please read the public API changes from here:
http://www.aspose.com/docs/display/wordsnet/Public+API+Changes+in+Aspose.Words+15.2.0

If you are using Aspose.Words version older then 15.2.0, please use the same code share in your first post with node type DrawingML and Shape to get the all images.

Please let us know if you have any more queries.