-
Notifications
You must be signed in to change notification settings - Fork 693
Open
Labels
Description
Describe the bug
If newPage() is called explicitly after it has already been called implicitly because the previous page was full, the header and footer are removed from the new page.
To Reproduce
Path output = Path.of("openpdf-test.pdf");
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(
document,
new FileOutputStream(output.toFile())
);
document.setHeader(new com.lowagie.text.HeaderFooter(false, new Phrase("Header")));
document.setFooter(new com.lowagie.text.HeaderFooter(false, new Phrase("Footer")));
document.open();
Font font = new Font(Font.HELVETICA, 12);
for (int i = 0; i < 50; i++) {
if(i == 37) {
// newPage() has already been called when the following line is executed, because Paragraph 37 is the first line on the new page.
document.newPage();
}
document.add(new Paragraph(
"This is line " + i + " of a long text to force automatic page breaks.",
font
));
}
document.close();Expected behavior
Header and footer should not be removed.
add initPage(); to PdfDocument after line 874:
public boolean newPage() {
lastElementType = -1;
if (isPageEmpty()) {
setNewPageSizeAndMargins();
resetText(true);
initPage();
return false;
}
...System
- OS: Windows / Linux
- OpenPDF version: master
Reactions are currently unavailable