PDF Page Numbering in Java & iText

caca picture caca · Jun 26, 2012 · Viewed 41k times · Source

I am creating some PDF reports using iText in Java. According to the requirements, what I should do is to number pages in the format of page_number/page_numbers_in_total.

However, memory operations burden my project. Hence, I don't want to go over all the pages again in order to number them. Is there any method to achieve that?

Answer

Alexis Pigeon picture Alexis Pigeon · Jun 26, 2012

Have a look at this example, which sets a similar header ("Page X of Y"):

You'll see that the onEndPage method prints the "Page X of ", and the onCloseDocument method sets the "Y" on all the pages through a PdfTemplate.