Issue Report: Table of Contents Placement in DocumentBuilder
Description of the Issue:
When adding a Table of Contents (TOC) to a document using DocumentBuilder, it is always placed on the first page, above all other content. This behavior occurs regardless of the intended page placement. I would like to place the TOC on a specific page of the document, but I have not been able to achieve this.
Steps to Reproduce:
1. Use the provided script to create a document with content and a TOC.
2. Add content and a page break before adding the TOC.
3. Generate and save the document as a PDF.
Example Script:
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Content");
oParagraph.SetBold(true);
oParagraph.SetFontSize(32);
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Some text here!");
oParagraph.AddPageBreak();
oDocument.Push(oParagraph);
var oTocPr = {
"ShowPageNums": true,
"RightAlgn": true,
"LeaderType": "dot",
"FormatAsLinks": true,
"BuildFrom": {"OutlineLvls": 9},
"TocStyle": "standard"
};
oDocument.AddTableOfContents(oTocPr);
oParagraph = Api.CreateParagraph();
oParagraph.SetStyle(oDocument.GetStyle("Heading 1"));
oParagraph.AddText("First Heading");
oDocument.Push(oParagraph);
builder.SaveFile("pdf", "TOC_test.pdf");
builder.Close();
Observed Behavior:
- The generated Table of Contents is always placed on the first page.
- The Table of Contents does not include any references to the headings, which is understandable given the content order, but its placement on the first page is not desired.
Expected Behavior:
The Table of Contents should be placed on a specific page of the document, as intended. For instance, after a cover page.
Screenshots:
Generated document preview:
Additional Information:
- DocumentBuilder Version: Latest
- Installation Method:
Downloaded the package from the official page and installed it usingsudo dnf install <package name>
. - Operating System: Fedora 40
Attachments:
- Script File: default_table_of_contents.docbuilder
- Generated File: TOC_test.pdf
Looking forward to guidance on how to properly place the TOC on a specific page. Thank you!