Free Support Forum -

Get Header image count

Dear Team,

We need to get the header image count from the input document through aspose.words java. Help us to resolve this.

Please find the attached input (461.5 KB)

Expected output :
Header Image Count: 2



Thanks for your inquiry. One simple way to get total images count from header is a follow:

    Document doc = new Document("D:\\Temp\\Documents\\input.docm");
            HeaderFooter firstHeader = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_FIRST);
            int imgCount = 0;
            for (Shape shape : (Iterable<Shape>)firstHeader.getChildNodes(NodeType.SHAPE, true))
                if (shape.hasImage())
            System.out.println("Total Images are: " + imgCount);

Thank you for the support.