Images count and list names of images embedded in word document

Hi team,

Requesting a work around solution to get the count and list of shapes

Images

Group Image (Consecutive images till a caption exists - to be considered as a single whole shape)

Charts

Images inside Table (To be considered as a single shape)

Equations

Thanks in advance,
regards,
priyanga G

@priyanga,

Thanks for your inquiry. Shape class represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture.

You can check either the shape has a chart or not using Shape.HasChart property. Please use CompositeNode.GetChildNodes method to get the collection of child nodes from table and document. Once you have this collection, you can get its size using NodeCollection.Count.

OfficeMath class represents an Office Math object such as function, equation, matrix or alike. Can contain child elements including runs of mathematical text, bookmarks, comments, other OfficeMath instances and some other nodes.

Please use the following code get the count of consecutive images. We already shared similar code with you in following forum thread.
Copy/Extract shape using paragraph node in JAVA

Document doc = new Document(MyDir + "in.docx");
ArrayList nodes = new ArrayList();

//Get the paragraphs that start with "Fig".
for (Paragraph  paragraph : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    if (paragraph.toString(SaveFormat.TEXT).trim().startsWith("Fig")) {
        Node previousPara = paragraph.getPreviousSibling();
        while (previousPara != null
                && previousPara.getNodeType() == NodeType.PARAGRAPH
                && previousPara.toString(SaveFormat.TEXT).trim().length() == 0
                && ((Paragraph) previousPara).getChildNodes(NodeType.SHAPE, true).getCount() > 0) {
            if (previousPara != null)
                nodes.add(previousPara);
            previousPara = previousPara.getPreviousSibling();
        }
    }
}

System.out.println(nodes.size());

Hi @tahir.manzoor ,

Apologize me for the delayed response.Thank you very much for your timely reply.

Thanks
Kind regards,
priyanga G