Examples

Adding Bookmarks & Outlines to PDF (.NET Core/Framework)

Bookmarks & Outlines to PDF can be added using Bookmark and Outline classes of DynamicPDF Generator.

How to add Bookmarks to PDF in C#

Below are the steps and sample code to add Bookmarks to PDF document using the Generator product.

Steps for Adding Bookmarks to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a Outline as a parent object on the document.
  4. Add top level Bookmark for each page as needed.
  5. Add child Bookmark for each page by specifying the parent outline.
  6. Add all the pages to the Document.
  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(@"C:\Output.pdf");        

How to add Outlines to PDF in C#

Below are the steps and sample code to add Outlines to PDF document using the Generator product.

Steps for Adding Outlines to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a Outline as a top level on the document and set properties.
  4. Add child outlines.
  5. Create as many top level outlines as needed.
  6. Add as many child outlines as needed.
  7. Save the PDF document.

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(@"C:\Output.pdf");        

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Generator Information

More information can be found here:

Available in other platforms

DynamicPDF Generator is available for the following platforms. 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 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

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