This sounds like the typical "list view from portal table context" method for printing an invoice. Are the number of lines per page consistent and predictable?
If there are no sliding fields to vary the number of line items per page, you can use the record's record number to to determine it's page number. With a field to show that page number, you can sort records by this field and use a sub summary layout part to show the page total.
The number of lines per page are are consistent and predictable to a certain extent. The first page would have up to X lines, the following pages up to Y lines and the final page the rest. I guess there is no "simple" solution. I can determine the number of line items for the first page and the following pages and then try to determine how many are then on the final page. Complicated but doable. I was hoping there might be a simpler solution.
There is a (fairly) simple calculation:
Ceiling ( ( Get ( RecordNumber ) + (Y - X ) ) / Y )
So if x = 30 and Y = 25
records 1 - 25 will be page 1. 26 - 55 will be page 2 and so forth....
You can find and sort the records to be used in printing the invoice, then use Replace Field Contents with the above calculation used to assign a page number to each record, then sort your records again in the same order as before but with page number added as the last field in the sort order.
A sub summary layout part can then show the page based subtotals. (Make sure to include the size of your sub summary layout part when you figure out how many records will fit on each page.