Update, September 2026Three things in this thread have moved on, so for anyone finding it:
"No ToC content control found" - the diagnosis above still applies. Word's table of contents is itself a content control (an SDT carrying w:docPartObj), and RemovalHandler with Quantifier.ALL removes
every content control in the main document part, TOC included. Either order the steps as suggested (bind, update the TOC, then remove), or use Quantifier.DEFAULT, which removes only the OpenDoPE condition and repeat controls and leaves the TOC's alone. From 17.0.4 the whole bind pipeline is the same across all three binding traversers, so this doesn't depend on which one you've configured.
Page numbers - the converter service (converter-eval.plutext.com) that updateToc(false) called in 2016 no longer exists, so the 502 in this thread is now a permanent "not there". Page numbers come from docx4j's own layout instead: put docx4j-export-fo on the classpath and updateToc lays the document out with Apache FOP and reads the page of each entry's bookmark. Two developments make that worth using:
- 17.1.0 reworked the FO output to follow Word's layout rules by default, measured against Word's page counts over a corpus of real documents, so the numbers now agree with what Word would print rather than drifting from it.
- 17.1.1 routes the TOC generator through the new org.docx4j.model.pagination.Paginate, the same machinery that can rewrite a document's w:lastRenderedPageBreak markers, so the TOC's numbers and the document's recorded pagination come from one layout.
If you have Word available on the machine, docx4j-documents4j-local drives Word itself for the layout, which is the other route.
If the docx will be turned into a PDF anyway, you can skip the numbers in the docx altogether: updateToc(true) for the entries, then export; the PAGEREF fields become fo:page-number-citation and FOP fills in the right numbers as it renders.
The dots - the leader fix referenced in the nightly build shipped in 3.3.2; the tab leader in the template's TOC style is honoured, and updateToc has an overload taking an STTabTlc if you want to force one.