How to detect page breaks in a .docx document using Apache POI?

I am trying to find page breaks in a .docx document using Apache POI. I do this to find the paragraph page number. The code I'm using is:

for (XWPFRun run : paragraph.getRuns()) { List<CTBr> brList = run.getCTR().getBrList(); if (brList != null && !brList.isEmpty()) { for (CTBr br : brList) { if (br.getType() == STBrType.PAGE) { //page break detected } } } else { List<CTEmpty> lastRenderedPageBreakList = run.getCTR().getLastRenderedPageBreakList(); if (lastRenderedPageBreakList != null) { for (CTEmpty lastRenderedPageBreak : lastRenderedPageBreakList) { //page break detected } } } } 

The code works fine for most pages, but not for all. Does anyone have an idea of ​​what I'm still missing?

+7
java parsing ms-word docx apache-poi
source share

No one has answered this question yet.

See similar questions:

0
Why are only some page numbers stored in the docx XML file?

or similar:

1729
How to break out of nested loops in Java?
nine
how to add image to .docx document using Apache POI XWPF in java
4
Apache POI: Extract paragraph and table that follow from Word document (docx) in java
2
Apache POI - Split Word Document (docx) per page
one
Failed to read more than 7 docx pages for String using Apache POI
one
Missing images in docx when pasting them using apache poi
one
Using Apache POI to Convert DOCX to PDF
one
Apache POI receives interrupt from XWPFRun
0
Convert .docx file to pdf using apache poi resets images
0
with Apache POI when converting the .docx format to json format.

All Articles