Adding Header and Footer in PDF using iText in Java

You may also like...

Subscribe
Notify of
guest
8 Comments
Oldest
Newest
Inline Feedbacks
View all comments
rozya
rozya
September 19, 2017 14:26

to get the right number of pages you need to replace String.valueOf(writer.getPageNumber()) by String.valueOf(writer.getPageNumber()-1) in public void onCloseDocument(PdfWriter writer, Document document)
thanks, the code was helpful

Rafa
Rafa
April 2, 2018 13:42
Reply to  rozya

Thanks!

Jakob Schade
Jakob Schade
January 19, 2018 14:41

I get an error with:
total = Image.getInstance(t);
total.setRole(PdfName.ARTIFACT);
//He doesn´t know total.setRole AND doesn´t know PdfName.ARTIFACT

AND
PdfContentByte canvas = writer.getDirectContent();
canvas.beginMarkedContentSequence(PdfName.ARTIFACT);
footer.writeSelectedRows(0, -1, 34, 50, canvas);
canvas.endMarkedContentSequence();
//He doesn´t know PdfName.ARTIFACT and tells me there are unsychronize things or something similar

alex
alex
September 15, 2018 12:17
Reply to  Jakob Schade

add only found in 5.5.9 itext

com.itextpdf
itextpdf
5.5.9

Rafa
Rafa
April 2, 2018 17:41

I have a problem with the footer, because it overlaps the text that I put in the body of the document. Do you know how I fix it so they do not overlap?

Aiden Tumwesigye
Aiden Tumwesigye
May 29, 2019 09:55

Thanks for this. has been very helpful. A few changes in this very code and i got my problem solved.

Armando
Armando
January 23, 2020 08:13

S’il existait un mot plus grand que MERCI, alors je l’aurais utilisé. Que Dieu vous bénéfice

8
0
Would love your thoughts, please comment.x
()
x