- Process the output from a
PdfWriterto abytestreamfirst with a dummy page count. - Create a
PdfReaderfrom thatbytestream, callingPdfReader.getNumberOfPagesto 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.