I am using the code below to generate ToC.
- Code: Select all
TocGenerator tocGenerator = new TocGenerator(wordMLPackage);
tocGenerator.generateToc( 8, " TOC \\o \"1-3\" \\h \\z \\u ", false);
Maven dependencies:
- Code: Select all
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
<version>8.3.1</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-export-fo</artifactId>
<version>8.3.1</version>
</dependency>
The exception
org.docx4j.toc.TocException: Exception exporting package
at org.docx4j.toc.TocGenerator.getPageNumbersMapViaFOP(TocGenerator.java:787) ~[docx4j-core-8.3.1.jar:na]
at org.docx4j.toc.TocGenerator.getPageNumbersMap(TocGenerator.java:650) ~[docx4j-core-8.3.1.jar:na]
at org.docx4j.toc.TocGenerator.populateToc(TocGenerator.java:397) ...