Add Bookmarks and Outlines to PDFs
Allow end users to quickly navigate to specific sections or pages of a PDF using bookmarks. DynamicPDF Core Suite for .NET makes adding bookmarks and outlines to a PDF a breeze, as the following C# examples illustrate.
How to Add Bookmark to PDF
The following steps and C# sample code illustrate how to add bookmarks to a PDF document using DynamicPDF Core Suite for .NET.
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
, specify its parent outline. - Add all the pages to the
Document
instance. - Add the
Draw
method to output 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 Outline to PDF
The following steps and C# sample code show how to add outlines to a PDF document using DynamicPDF Core Suite for .NET.
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's Outlines collection. - Create two child outlines and add them to the parent outline..
- Add the
Draw
method to output 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(@"Output.pdf");
GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - BookmarkOutlineExample.cs
- VB.NET - BookmarkOutlineExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Outlines and Bookmarks
- Refer to the Outlines and Bookmarks documentation topic, or
- Chapter 13, Outlines and Bookmarks, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX