Search in sources :

Example 1 with TocGenerator

use of org.docx4j.toc.TocGenerator in project flexmark-java by vsch.

the class CoreNodeDocxRenderer method renderDocument.

@Override
public void renderDocument(final DocxRendererContext docx, final Document document, final DocxRendererPhase phase) {
    // here non-rendered elements can be collected so that they are rendered in another part of the document
    switch(phase) {
        case COLLECT:
            break;
        case DOCUMENT_TOP:
            enumeratedOrdinals = EnumeratedReferenceExtension.ENUMERATED_REFERENCE_ORDINALS.getFrom(document);
            break;
        case DOCUMENT_BOTTOM:
            if (options.tocGenerate || lastTocBlock != null) {
                TocGenerator tocGenerator = null;
                try {
                    tocGenerator = new TocGenerator(docx.getPackage());
                    tocGenerator.setStartingIdForNewBookmarks(docx.getBookmarkIdAtomic());
                    // tocGenerator.generateToc( 0,    "TOC \\o \"1-3\" \\h \\z \\u ", true);
                    tocGenerator.generateToc(0, options.tocInstruction, true);
                } catch (TocException e) {
                    if (tocGenerator != null && e.getMessage().contains("use updateToc instead")) {
                        try {
                            tocGenerator.updateToc(true);
                        } catch (TocException e1) {
                            e1.printStackTrace();
                        }
                    } else {
                        e.printStackTrace();
                    }
                }
            // to generate page numbers, you should install your own local instance of Plutext PDF Converter,
            // and point to that in docx4j.properties
            // tocGenerator.generateToc( 0,    "TOC \\h \\z \\t \"comh1,1,comh2,2,comh3,3,comh4,4\" ", true);
            }
            break;
        default:
            break;
    }
}
Also used : TocException(org.docx4j.toc.TocException) TocGenerator(org.docx4j.toc.TocGenerator)

Aggregations

TocException (org.docx4j.toc.TocException)1 TocGenerator (org.docx4j.toc.TocGenerator)1