- Process the output from a
PdfWriter
to abytestream
first with a dummy page count. - Create a
PdfReader
from thatbytestream
, callingPdfReader.getNumberOfPages
to get the actual page count. - Recreate the PDF output, knowing what the page count will be, changing the footer accordingly.
It’s messy, but there’s no easy way to know the page count without a two-pass approach. See the example code for details on manipulating PDFs.