We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extracting Inline images from Word document

@Saranya_Sekar,

The last image at the end of document is also an inline image. As shown in the following screenshot:

All three images are part of the same Paragraph. So, this is expected behavior and you need to modify the source document to get the desired results.

@awais.hafeez
I again find some other images other than inline images are extracted help please. Input is ManuscriptCDTe QDs Final211.zip (1.4 MB)
and the output extracted is ManuscriptCDTe QDs Final211 -shape.zip (202.7 KB)
Help please. can you please share the code.

@Saranya_Sekar,

I am afraid, the big figure on page 4 of “ManuscriptCDTe QDs Final211.doc” is also inline and you can verify it inside Document.xml file. If we can help you with anything else, please feel free to ask.

@awais.hafeez

The image 1 in this input document is not retrieved it is extracted as bit 0 kb. Kindly suggest how to get the correct image. The input I used is Anchored_Images.zip (2.6 MB)
and the interim generated is Anchored_Images_Interim (2).zip (13.4 KB)
and the output file is Anchored_Images (2).zip (2.6 MB) Kindly help please

@Saranya_Sekar,

Please try using the following code and see these output documents output.zip (2.6 MB).

Document doc = new Document("D:\\temp\\Anchored_Images (2)\\Anchored_Images.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

int i = 1;
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {

    if (shape.getParentParagraph() == null ||
            shape.getParentParagraph().getChildNodes().getCount() == 1 ||
            shape.getAncestor(NodeType.TABLE) != null ||
            shape.getShapeType() == ShapeType.TEXT_BOX) {

    } else {
        Document newDoc = (Document) doc.deepClone(false);
        newDoc.removeAllChildren();
        newDoc.ensureMinimum();

        Shape importedShape = (Shape) newDoc.importNode(shape, true);
        importedShape.setWrapType(WrapType.NONE);
        importedShape.setHorizontalAlignment(HorizontalAlignment.CENTER);
        importedShape.setVerticalAlignment(VerticalAlignment.CENTER);
        importedShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        importedShape.setRelativeHorizontalPosition(RelativeVerticalPosition.PAGE);

        newDoc.getFirstSection().getBody().getFirstParagraph().appendChild(importedShape);

        builder.moveTo(shape);
        builder.getFont().setColor(Color.red);
        builder.write(" <Inline-Img>Inline-Img" + i + "</Inline-Img> ");

        shape.remove();

        newDoc.save("D:\\temp\\Anchored_Images (2)\\shape_" + i + ".docx");
    }
    i++;
}

doc.save("D:\\temp\\Anchored_Images (2)\\out.docx");