Free Support Forum - aspose.com

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 document:input1.zip (461.5 KB)

Expected output :
Header Image Count: 2

Regards,
Suruthy

@suruthyb

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())
                    imgCount++;
            }
            System.out.println("Total Images are: " + imgCount);

@mannanfazil
Thank you for the support.