I do not have an input document - from looking for other posts on this topic, I’ve found that the LayoutCollector and LayoutEnumerator classes are incapable of finding nodes in headers and footers, which causes my solution to error. the way we construct our headers/footers, they are always a table of one row and three cells, so I came up with this, which would calculate cell heights, and return the tallest one (if it worked), passing in the table and builder once the table is created:
private double getHeaderFooterHeight(
Table table, DocumentBuilder builder) throws Exception {
Document doc = builder.getDocument();
doc.updatePageLayout();
LayoutCollector lc = new LayoutCollector(doc);
LayoutEnumerator le = new LayoutEnumerator(doc);
double headerFooterHeight = 0;
double cellHeight = 0;
CellCollection cells = table.getLastRow().getCells();
for (Cell cell : cells) {
ParagraphCollection paragraphs = cell.getParagraphs();
for (Paragraph para : paragraphs) {
le.setCurrent(lc.getEntity(para));
double paragraphHeight = le.getRectangle().getHeight();
cellHeight += paragraphHeight;
}
if (cellHeight > headerFooterHeight) {
headerFooterHeight = cellHeight;
}
}
return headerFooterHeight;
}
does this help? our documents only have a primary header/footer, there are no other types, so each page has the same header/footer.