using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.interaction.navigation.document;
using it.stefanochizzolini.clown.files;
using it.stefanochizzolini.clown.objects;
using System;
namespace it.stefanochizzolini.clown.samples{
/**
<summary>This sample demonstrates how to inspect the bookmarks of a PDF document.</summary>
*/
public class BookmarksParsingSample
: ISample
{
public void Run(
SampleLoader loader
)
{
// (boilerplate user choice -- ignore it)
string filePath = loader.GetPdfFileChoice("Please select a PDF file");
// 1. Open the PDF file!
File file = new File(filePath);
// Get the PDF document!
Document document = file.Document;
// 2. Get the bookmarks collection!
Bookmarks bookmarks = document.Bookmarks;
if(bookmarks == null)
{
Console.WriteLine("\nNo bookmark available (Outline dictionary doesn't exist).");
return;
}
Console.WriteLine("\nIterating through the bookmarks collection (please wait)...\n");
// 3. Show the bookmarks!
PrintBookmarks(bookmarks);
}
private void PrintBookmarks(
Bookmarks bookmarks
)
{
if(bookmarks == null)
return;
foreach(Bookmark bookmark in bookmarks)
{
// Show current bookmark!
Page page = bookmark.Destination.Page;
Console.WriteLine("Bookmark '" + bookmark.Title + "'");
Console.WriteLine(" Target Page: number = " + (page.Index + 1) + "; ID = " + ((PdfReference)page.BaseObject).ID);
// Show child bookmarks!
PrintBookmarks(bookmark.Bookmarks);
}
}
}
}
|