For pages that I generate, my data is pre-processed from a database into an array of hashes. So each slot in the array is a page. No need to go back and place page numbers, just get the total page count from
, and then increment the current page number using a variable within the loop. This method may not work very well though if you are generating thousands of pages per document.