Hi there,
I wrote some code to add some headings into the document. But I also want to that they are numerated by a list.
That works fine but now I would like to set the left-intend of the headings to zero so that the numbers of the heading starting at the end of the page margins.
For the first two levels it works but there is an issue when I insert a level three heading or higher.
Document document = new Document();
document.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2013);
DocumentBuilder builder = new DocumentBuilder(document);
builder.getPageSetup().setPaperSize(PaperSize.A4);
/*============ Preparing Heading List ============*/
List headings = document.getLists().add(ListTemplate.NUMBER_ARABIC_DOT);
Style heading1 = document.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1);
heading1.getListFormat().setList(headings);
heading1.getListFormat().setListLevelNumber(0);
heading1.getListFormat().getListLevel().setNumberFormat("\u0000.");
heading1.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
heading1.getParagraphFormat().setLeftIndent(0);
heading1.getParagraphFormat().setFirstLineIndent(0);
heading1.getFont().setSize(18);
Style heading2 = document.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_2);
heading2.getListFormat().setList(headings);
heading2.getListFormat().setListLevelNumber(1);
heading2.getListFormat().getListLevel().setNumberFormat("\u0000.\u0001.");
heading2.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
heading2.getParagraphFormat().setLeftIndent(0);
heading2.getParagraphFormat().setFirstLineIndent(0);
heading2.getFont().setSize(16);
Style heading3 = document.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_3);
heading3.getListFormat().setList(headings);
heading3.getListFormat().setListLevelNumber(2);
heading3.getListFormat().getListLevel().setNumberFormat("\u0000.\u0001.\u0002.");
heading3.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
heading3.getParagraphFormat().setLeftIndent(0);
heading3.getParagraphFormat().setFirstLineIndent(0);
heading3.getFont().setSize(14);
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
builder.writeln("Heading first level");
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
builder.writeln("Heading second level");
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);
builder.writeln("Heading third level");
document.save("HeadingTest.docx");
Here is the result of the code: HeadingTest.zip (5.7 KB)
Thank you