Examples

Adding Bookmarks & Outlines to PDF

Bookmarks and Outlines can be added to a PDF document using the DynamicPDF Core Suite Bookmark and Outline classes.

How to Add Bookmarks to a PDF in C#

Below are the steps and sample code to add bookmarks to a PDF document using DynamicPDF Core Suite.

Steps for Adding Bookmarks to a PDF Document

  1. Create a Document object.
  2. Create three Page objects.
  3. Create a Outline as a parent object to the document.
  4. Add four top level Bookmark object instances, one for each Page instance.
  5. For each child Bookmark, specifying its parent outline.
  6. Add all the pages to the Document instance.
  7. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page1 = new Page( PageSize.Letter );
Page page2 = new Page( PageSize.Letter );
Page page3 = new Page( PageSize.Letter );

Outline parentOutline = document.Outlines.Add( "Parent Outline" );

page1.Elements.Add( new Bookmark( "Top level bookmark to page 1", 0, 0 ) );

page1.Elements.Add( new Bookmark( "Bookmark to page 1", 0, 0, parentOutline ) );
page2.Elements.Add( new Bookmark( "Bookmark to page 2", 0, 0, parentOutline ) );
page3.Elements.Add( new Bookmark( "Bookmark to page 3", 0, 0, parentOutline ) );

document.Pages.Add( page1 );
document.Pages.Add( page2 );
document.Pages.Add( page3 );

document.Draw(@"Output.pdf");        

How to Add Outlines to PDF in C#

Below are the steps and sample code to add outlines to a PDF document using DynamicPDF Core Suite.

Steps for Adding Outlines to a PDF Document

  1. Create a Document object.
  2. Create three Page objects.
  3. Create an Outline instance and add it the the Document object's Outlines collection.
  4. Create two child outlines and add them to the parent outline..
  5. Output the PDF document by invoking the Document object's Draw method.

Sample Code - C#

Document document = new Document();
document.Pages.Add(new Page(PageSize.Letter));
document.Pages.Add(new Page(PageSize.Letter));
document.Pages.Add(new Page(PageSize.Letter));

Outline outline1 = document.Outlines.Add( "Outline1" );
outline1.Style = TextStyle.Bold;
outline1.Color = new RgbColor( 1.0f, 0.0f, 0.0f );

Outline outline1A = outline1.ChildOutlines.Add( "Outline1A", new ZoomDestination( 2, PageZoom.FitPage ) );
outline1A.Expanded = false;
Outline outline1A1 = outline1A.ChildOutlines.Add( "Outline1A1", new XYDestination( 2, 0, 0 ) );
Outline outline1A2 = outline1A.ChildOutlines.Add( "Outline1A2", new ZoomDestination( 2, PageZoom.FitHeight ) );
Outline outline1B = outline1.ChildOutlines.Add( "Outline1B", new ZoomDestination( 2, PageZoom.FitWidth ) );

Outline outline2 = document.Outlines.Add( "Outline2", new XYDestination( 3, 0, 300 ) );
Outline outline2A = outline2.ChildOutlines.Add( "Outline2A" );

document.Draw(@"Output.pdf");        

GitHub Project

Clone or view the example project at GitHub. This example code is contained in the Examples/BookmarkOutlineExample.cs file.

Clone or View Example Project on GitHub

Getting Started

NuGet Package

DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The easiest way to install the package is through the Visual Studio Package Manager; however, you can also download the package directly on NuGet.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information

More information on DynamicPDF Core Suite can be found at the following webpage.

Available on Other platforms

DynamicPDF Core Suite is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!