ParserGetToc Method
Extracts a table of contents from the document.

Namespace: GroupDocs.Parser
Assembly: GroupDocs.Parser (in GroupDocs.Parser.dll) Version: 20.10.0
Syntax
public IEnumerable<TocItem> GetToc()

Return Value

Type: IEnumerableTocItem
A collection of table of contents items; null if table of contents extraction isn't supported.
Remarks
Examples

The following example shows how to extract table of contents from CHM file:

C#
// Create an instance of Parser class
using (Parser parser = new Parser(filePath))
{
    // Check if text extraction is supported
    if (!parser.Features.Text)
    {
        Console.WriteLine("Text extraction isn't supported.");
        return;
    }

    // Check if toc extraction is supported
    if (!parser.Features.Toc)
    {
        Console.WriteLine("Toc extraction isn't supported.");
        return;
    }

    // Get table of contents
    IEnumerable<TocItem> toc = parser.GetToc();

    // Iterate over items
    foreach (TocItem i in toc)
    {
        // Print the Toc text
        Console.WriteLine(i.Text);
        // Check if page index has a value
        if (i.PageIndex == null)
        {
            continue;
        }
        // Extract a page text
        using (TextReader reader = parser.GetText(i.PageIndex.Value))
        {
            Console.WriteLine(reader.ReadToEnd());
        }
    }
}
See Also