I would throw away the code that writes the header along with the rest of the data, and introduce a page event that adds the header in the OnEndPage()
event.
To deal with the fact that you only know the total when page X is reached whereas you may need that total on pages X - 1, X -2,... I would use a PdfTemplate
(as mkl suggests).
This is demonstrated in examples such as MovieCountries1
(see http://tinyurl.com/itextsharpIIA2C04 for the C# counterpart).
Using a page event has the benefit that you don't need to keep track of the pages, you can keep the code that draws the header separate from the rest of the business logic. See http://itextpdf.com/sandbox/events/ for some more examples.