I did not find a way to do this automatically. But the following works:
- Reserve a page for the TOC
- Build the remaining document
- Insert the TOC on the reserved page and loop through the remaining sections and generate the TOC row by row. Page numbers of the sections are found using the
DynamicDocumentPaginator
Note: If the TOC will span multiple pages more than one iteration is needed.