How to extract the table of contents
Example
using System;
namespace VersOne.Epub.ConsoleDemo
{
internal static class PrintNavigation
{
public static void Run(string filePath)
{
using (EpubBookRef bookRef = EpubReader.OpenBook(filePath))
{
Console.WriteLine("Navigation:");
foreach (EpubNavigationItemRef navigationItemRef in bookRef.GetNavigation())
{
PrintNavigationItem(navigationItemRef, 0);
}
}
Console.WriteLine();
}
private static void PrintNavigationItem(EpubNavigationItemRef navigationItemRef, int identLevel)
{
Console.Write(new string(' ', identLevel * 2));
Console.WriteLine(navigationItemRef.Title);
foreach (EpubNavigationItemRef nestedNavigationItemRef in navigationItemRef.NestedItems)
{
PrintNavigationItem(nestedNavigationItemRef, identLevel + 1);
}
}
}
}
See it in action
Download the .NET console demo app, run it, and select the 1. Print book navigation tree (table of contents) option.