ParserGetToc Method |
Namespace: GroupDocs.Parser
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()); } } }