Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

Generating Table Of Contents (TOC): Practical Guide

$
0
0

This example illustrates the simplest approaches to generate a TOC for a given source document.

Lets imagine that you have obtained a document and you need to generate a TOC for this document. Here are the steps you need to execute for this purpose:

1) Decide which parts for the document should be TOC entries.
This step is specific to your document. For instance, this document might contain several headings in the following form: "Chapter NoXY". Generally, you can use Search API (see the Using the Search and Replace API functionality and Search API - An example of use examples) to find the position of these parts in the document. In this particular example, we search for TOC entries (see the SearchForTOCEntries() method) by examining the font size of the paragraphs. This approach is based on the How to list fonts that are used in a document code example.

2) Mark TOC entries in a special manner.
This step is required because the TOC field, which will be added in the next step, should be able to recognize document parts as a TOC entries when this field is updated (see Fields to learn more). We can use the following simple approaches:

- Paragraph styles with set outline levels
You need to create and apply ParagraphStyles with specific ParagraphPropertiesBase.OutlineLevel Property values. Take a moment to look at the How to create and apply document styles code example to learn more about Styles API.

- Outline levels
Simply apply specific outline levels to paragraphs considered TOC entries

- TC fields
Insert TC fields in the document. We have a code example that illustrates how to insert fields in code: How to create nested fields programmatically

3) Add a TOC field to the document and update this field (see the InsertTOC() method).
A TOC field should have switches that correspond to the method in which TOC entries are marked in the previous step.

Here is a screenshot that illustrates the operation of a sample application:

Take a moment to look at the Rachel Reese - DevExpress Scheduler & RichEdit Blog and related webinar to learn the basics of the TOC feature.

Question Comments

Added By: Genesis Supsup at: 5/16/2016 8:17:23 PM    Is this feature working in the ASP.Net compoenent?

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>