Add a Table of Contents (TOC)
- 3 minutes to read
This tutorial adds a table of contents (TOC) to a report. You start with a master-detail report, specify bookmarks for report controls, add an XRTableOfContents
control to the form, specify its title, and apply custom formatting to TOC entries at different nesting levels.
Overview
A table of contents (TOC) displays page numbers for bookmarked report elements at different nesting levels.
The following image displays a table of contents in a report designer and in a published document:
A table of contents contains the following elements:
- Title
- The XRTableOfContentsTitle class defines the title text and format. Use the XRTableOfContents.LevelTitle property to access the TOC title.
- Levels
You can specify one or more levels. The XRTableOfContentsLevel class defines format settings for nodes in a document map tree.
To access the collection of levels, use the XRTableOfContents.Levels property.
The table of contents initially includes one default level. It specifies common settings for elements of the document map that do not yet have a specific level assigned to them.
If you export a report to a tagged PDF (accessibility-compliant format like PDF/UA a table of content is automatically converted into TOCI
entries. These entries help screen readers and accessibility tools interpret the PDF document’s structure.
You can see a TOC example in the following demo:
Create a Table of Contents
Create a master-detail report with the following layout:
- Specify bookmarks for report elements that need to be included in the table of contents.
Open the Toolbox panel (by pressing CTRL+ALT+X), select the XRTableOfContents control in the DX.25.1: Report Controls category and drop it onto the report surface. The control appears on the Report Header band. This band is created automatically if the report does not have one.
Customize the table of contents title using the XRTableOfContents.LevelTitle property.
When report bookmarks are organized into a hierarchy (by setting the nested elements’ XRControl.BookmarkParent property), the corresponding levels are displayed in the table of contents. You can specify each level’s text formatting options individually.
Access the level collection by clicking the control’s smart tag and using the XRTableOfContents.Levels property.
In the collection editor, click Add to add a new level and adjust its settings.
You can limit the maximum number of levels the table of contents displays using the XRTableOfContents.MaxNestingLevel property.
The XRTableOfContents.LevelDefault property allows you to specify common level formatting settings. These settings apply to levels that you did not customize explicitly.
The following image demonstrates the result in Print Preview: