PDF .NET Library Logo

Creating Bookmarks in a PDF document

The following code snippet creates PDF bookmarks that appear in the left side bar of Acrobat.

C# sample:

PDFCreationOptions options = new PDFCreationOptions();

options.Viewer.PageMode = PageMode.UseOutlines;

PDFDocument MyPDF = new PDFDocument("Bookmarks.pdf", options);

for(int i = 0; i < 10; i++)

{

if(i != 0) MyPDF.NewPage();

}

PDFGoToPageAction act = MyPDF.CreateGoToPageAction(0, 0);

PDFOutlineNode root = MyPDF.Outlines.Add(null, "Bookmarks", act, Charset.ANSI_CHARSET);

root.Expanded = true;

for(int i = 0; i < MyPDF.Pages.Count; i++)

{

// Create child bookmark

      act = MyPDF.CreateGoToPageAction(i, 0);

      PDFOutlineNode chapter = MyPDF.Outlines.AddChild(root, "Page " + (i + 1).ToString(), act, Charset.ANSI_CHARSET);

      chapter.Expanded = true;

      chapter.Color = Color.Blue;

      chapter.Style = FontStyle.Italic;

}

MyPDF.Save();

Back to PDF Code Library