Find figure page number

Dear team,

I have tried to find images located pages, page numbers. But i’m notable to get proper page numbers> please find below source code

public static int pagenumber(Document interimdoc, String sd) throws Exception {
	Document doc = interimdoc;
	int pageNumber = 0;
	String figure = "";
	String fig = "";
	StringTokenizer sd1 = new StringTokenizer(sd, "@@");
	while (sd1.hasMoreTokens()) {
		String fg = sd1.nextToken();
		if (fg.startsWith("Fig")) {
			fig = fg;
			fig = fig.replace("Fig", "Fig. ");
			Pattern pattern1 = Pattern.compile("0");
			Matcher matcher1 = pattern1.matcher(fig);
			fig = matcher1.replaceAll("");
			figure = fg;
			figure = figure.replace("Fig", "Figure ");
			Pattern pattern = Pattern.compile("0");
			Matcher matcher = pattern.matcher(figure);
			figure = matcher.replaceAll("");
		}
	}
	NodeCollection<Paragraph> paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);

	for (Paragraph paragraph : (Iterable<Paragraph>) paragraphs) {
		try {
			if ((paragraph.toString(SaveFormat.TEXT).trim().startsWith(figure))
				|| (paragraph.toString(SaveFormat.TEXT).trim().startsWith(fig))) {
				LayoutCollector lc = new LayoutCollector(doc);
				pageNumber = lc.getStartPageIndex(paragraph);
			}
		} catch (Exception e) {
			}
	}
	return pageNumber;
}

input file : Supporting information_Girard-Sahun et al._revised.docx (1.7 MB)

please do need full

@e503824 The code you have provided loops through all paragraphs in the document and as a result it returns page number of the last paragraphs that passes the condition. If you need to get page numbers of images in your code you can use code like the following:

Document doc = new Document("C:\\Temp\\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
Iterable<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape s : shapes)
{
    if (s.hasImage())
    {
        System.out.println(collector.getStartPageIndex(s));
    }
}