Hi,
We are currently using Aspose Words Java version in our application.
The LayoutEnumerator API is not able to detect PAGE nodes when the document contains FOOTNOTE element after “Section Break” element.
We ran the below code with the latest Aspose Words Java version 23.9.0.
Use the attached “TestData.docx” file when running below code.
The attached test document has total 5 pages, but the below code traverses thru and detects only first 2 pages (BUG).
What we observed is, when there is a “Footnote” element after the “Section Break” element in a particular page, then the LayoutEnumerator API fails to detect the PAGE node in that page, and it does NOT advance the layout entity traversal to the subsequent pages. Thus, the traversal get stuck and it doesn’t proceed on to the subsequent pages in the document.
Run the below code:
public static void main(String[] args) throws Exception {
Document doc = new Document("TestData.docx");
int numberOfPages = doc.getPageCount();
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
List<Integer> pageNumbersFound = new ArrayList<>();
for (int pageIndex = 0; pageIndex < numberOfPages; pageIndex++) {
pageNumbersFound.add(traverseLayoutEntities(enumerator));
}
System.out.println("Page numbers found: " + pageNumbersFound);
}
// Traverses the layout elements in the current page.
// Returns the current page number if the PAGE node is found. Otherwise returns -1.
private static int traverseLayoutEntities(LayoutEnumerator enumerator) throws Exception {
do {
if (enumerator.moveLastChild()) {
traverseLayoutEntities(enumerator);
enumerator.moveParent();
}
if (enumerator.getType() == LayoutEntityType.PAGE) {
int pagerNumberFound = enumerator.getPageIndex();
enumerator.moveNext();
return pagerNumberFound; // Page node found.
}
} while (enumerator.movePrevious());
return -1; // Page node not found.
}
When we run the above code, it prints
Page numbers found: [1, 2, -1, -1, -1]
But we expect the following to be printed
Page numbers found: [1, 2, 3, 4, 5]
Can you please check this.
Let us know if we miss something in the above code or if there any workaround code for this issue.
TestData.docx (16.1 KB)
Thanks,
-Satya