How to add the total page number on every page with iText?
bytestreamfirst with a dummy page count.
PdfReader.getNumberOfPagesto get the actual page count.
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.