Nevron Open Vision Documentation
Table Of Contents

The table of contents block lets you easily create and maintain an up to date table of contents for a rich text document.

Paragraph Outline Level

Paragraphs expose a property called OutlineLevel that determines the level of the paragraph's text when placed in a table of contents. The default value of this property is BodyText, which means that the paragraph will not be included in the table of contents. If you change the value of the property to a value from Level1 to Level9, then the paragraph's text will be included in the table of contents.

In the most cases you will not change the outline level of the paragraph but rather apply one of the heading styles (e.g. "Heading1") to it. The heading styles set the OutlineLevel of the paragraphs they are applied to through styling. The following code example demonstrates how to apply a heading style to a paragraph:

Applying a heading style to a paragraph
Copy Code
// Get a reference to the "Heading1" style
NRichTextStyle heading1Style = richTextView.Content.Styles.GetStyleByTypeAndName(ENRichTextStyleType.Paragraph, "Heading1");

// Create and style a paragraph
Paragraph paragraph = new NParagraph("Chapter 1");
section.Blocks.Add(paragraph);
heading1Style.Apply(paragraph);

After the "Heading1" style is applied to the paragraph, it will have an outline level of 1 and will be included in a table of contents.

Table of Contents Block

To add a table of contents to a rich text document, simply create an NTableOfContentsBlock and add it to the document.

Creating a table of contents block
Copy Code
NTableOfContentsBlock tableOfContents = new NTableOfContentsBlock();
section.Blocks.Add(tableOfContents);

When you want to update the table of contents, simply call its Update method. Note that if the rich text view's document is not yet evaluated, you should call the Evaluate method of the rich text view document first.

Updating a table of contents block
Copy Code
richTextView.Document.Evaluate();
tableOfContents.Update();
Customizing the Table of Contents

By default the table of contents block's title is "Table of Contents". If you want to change that default title you should create and add a paragraph to the table of content's collection of blocks or simply use the AddTitleParagraph method as shown in the following code snippet:

Table of contents block with custom title
Copy Code
NTableOfContentsBlock tableOfContents = new NTableOfContentsBlock();
section.Blocks.Add(tableOfContents);
tableOfContents.AddTitleParagraph("My Cutsom Title");

The table of contents block also relies on the "TOCHeading" of the table of contents title and from the "TOC1" to the "TOC9" styles for the table of contents entries. You can modify any of these styles if you want to change the appearance of your table of contents. The following code example demonstrates how to make the title of a table of contents red and the first level table of content entries - blue:

Table of contents block styles
Copy Code
NParagraphStyle tocHeadingStyle = (NParagraphStyle)documentBlock.Styles.GetStyleByTypeAndName(
    ENRichTextStyleType.Paragraph, "TOCHeading");
tocHeadingStyle.InlineRule.Fill = new NColorFill(NColor.Red);

NParagraphStyle toc1Style = (NParagraphStyle)documentBlock.Styles.GetStyleByTypeAndName(
    ENRichTextStyleType.Paragraph, "TOC1");
toc1Style.InlineRule.Fill = new NColorFill(NColor.Blue);
See Also

Styles

Send Feedback