GetToc
Parser.GetToc method
Extracts a table of contents from the document.
public IEnumerable<TocItem> GetToc()
Return Value
A collection of table of contents items; null
if table of contents extraction isn’t supported.
Remarks
Learn more:
- Extract table of contents
- Extract text by table of contents item
- Extract table of contents from Microsoft Office Word documents
- Extract table of contents from EPUB eBooks
Examples
The following example shows how to extract table of contents from CHM file:
// 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
- class TocItem
- class Parser
- namespace GroupDocs.Parser
- assembly GroupDocs.Parser