AddTableOfContents
Adds a table of content to the current document. 💡 Please note that the new table of contents replaces the existing table of contents.
Syntax
expression.AddTableOfContents(oTocPr);
expression
- A variable that represents a ApiDocument class.
Parameters
Name | Required/Optional | Data type | Default | Description |
---|---|---|---|---|
oTocPr | Optional | TocPr | {} | Table of contents properties. |
Returns
boolean
Example
This example adds a table of content to the document.
- Code
- Result
// How to add headings to the document and generate a table of contents.
// Insert a table of contents specifying its properties.
let doc = Api.GetDocument();
let newDocumentStyle = doc.GetStyle("Heading 1");
let paragraph = doc.GetElement(0);
paragraph.SetStyle(newDocumentStyle);
paragraph.AddText("Heading 1");
newDocumentStyle = doc.GetStyle("Heading 2");
paragraph = Api.CreateParagraph();
paragraph.SetStyle(newDocumentStyle);
paragraph.AddText("Heading 2");
doc.Push(paragraph);
let tocPr = {"ShowPageNums": true, "RightAlgn": true, "LeaderType": "dot", "FormatAsLinks": true, "BuildFrom": {"OutlineLvls": 9}, "TocStyle": "standard"};
doc.AddTableOfContents(tocPr);