I’m trying to exclude certain headings from the “table of content”.
Since I did not find another way, I’m trying to set a different style on the paragraph (“Heading 1 no_index”).
Style heading1 = contentDocument.getStyles().get(StyleIdentifier.HEADING_1);
Style noIndex = contentDocument.getStyles().addCopy(heading1);
noIndex.setName("Heading 1 no_index");
System.out.println("Heading 1: " + heading1.isHeading() + " " + heading1.getStyleIdentifier());
System.out.println("Heading 1 no_index: " + noIndex.isHeading() + " " + noIndex.getStyleIdentifier());
This outputs the following (so the new style is no heading anymore):
Heading 1: true 1
Heading 1 no_index: false 4094
On the actual heading paragraph I do the following:
ParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
Style noIndex = parent.getDocument().getStyles().get("Heading 1 no_index");
paragraphFormat.setStyle(noIndex);
In the end the heading is still listed in the “table of content”.
How can I accomplish, keeping the formatting but not listing the title in the TOC?