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
- Create a
Document
object. - Create three
Page
objects. - Create a
Outline
as a parent object to the document. - Add four top level
Bookmark
object instances, one for eachPage
instance. - For each child
Bookmark
, specifying its parent outline. - Add all the pages to the
Document
instance. - 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
- Create a
Document
object. - Create three
Page
objects. - Create an
Outline
instance and add it the theDocument
object'sOutlines
collection. - Create two child outlines and add them to the parent outline..
- Output the PDF document by invoking the
Document
object'sDraw
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.
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.
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.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX