Skip to content

Instantly share code, notes, and snippets.

@conholdate-docs-gists
Created October 20, 2022 11:11
Show Gist options
  • Save conholdate-docs-gists/ffe75c341b0c907513d8ae08f6d4d3d2 to your computer and use it in GitHub Desktop.
Save conholdate-docs-gists/ffe75c341b0c907513d8ae08f6d4d3d2 to your computer and use it in GitHub Desktop.
// 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());
}
}
}
@conholdate-docs-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment