In This Topic
C1PrintDocument supports automatic generation of table of contents (TOC). The table of contents itself is represented by a dedicated render object, RenderToc, which is derived from RenderArea and adds TOC-specific features. Individual items within the TOC are represented by RenderTocItem (derived from RenderParagraph). Each TOC item holds a hyperlink (the RenderTocItem.Hyperlink property) pointing to a location in the document (represented by an anchor). So, the same mechanism is used for connecting TOC items to document content as for hyperlinks. Convenient methods are provided to create the TOC, see below.
To add a table of contents to your document, do the following:
- Create an instance of the RenderToc class and add it to your document at the point where you want the TOC to appear.
- Add individual items (of the type RenderTocItem) to the RenderToc instance. Any of the following approaches (or a mix of them) may be used for this:
- You may add the TOC item to the TOC using any of the overloads of the RenderToc.AddItem method, providing the text of the item, the location it should point to, and optionally the level in the TOC.
- You may create an instance of the RenderTocItem class in your code, set properties on it, and add it to the Children collection of the TOC render object.
- An overload of the RenderTocItem constructor is provided which accepts an instance of the RenderToc as the argument. When that constructor is used, the newly created TOC item is added to the TOC within the constructor, so you do not need to add it to the Children collection of the TOC object manually.
For a complete sample of how to create the table of contents for a document using the dedicated RenderToc render object, see the RenderTOC sample installed in the ComponentOne Samples folder.