javapdfitextpage-numbering

PDF Page Numbering in Java & iText


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?


Solution

  • 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.