Although not efficient, I found two solutions: one is to generate the files separately and merge them via a user control, another is to generate them separately as "temporary files", receive the length of the document as an output parameter (the &Page variable) and use this parameter as a total for the corresponding section. Then I delete the temporary file.
Pretty crude, but it worked