0

I want to add table of contents(toc) on 3rd page of Doc using apache XWPF.

Here is the code below : 

XWPFDocument doc = new XWPFDocument();

CTSdtBlock block = doc.getDocument().getBody().addNewSdt();
           TOC toc = new TOC(block);
                 toc.addRow(3, "toc", 3, "16283778");
        doc.write(new FileOutputStream(new File("toc.docx")));
Aman Kumayu
  • 381
  • 1
  • 9
  • This is a duplicate because any attempt to customize the Table of Contents can be handled as in the accepted answer. If you can't figure out this particular customization after reading the duplicate question and answer, edit this question with your specific point of confusion in relation to the linked question and answer. – jmarkmurphy Oct 23 '17 at 12:04

1 Answers1

0

I think you should create a paragraph in your document with a run. That way you can add BreakType.PAGE to your paragraphs.

XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.addBreak(BreakType.PAGE);

BreakType.PAGE skips a page

Patrick
  • 331
  • 3
  • 18