Bookmarks & outlines
Bookmarks give readers shortcuts to important sections in a longer PDF. Create navigation trees for two three-page PDFs using the Fluent API. This example follows BookmarksPdf.cs and demonstrates page bookmarks, nested outlines, text styling, and destination settings.
Create document navigation with bookmarks and outline classes.
What you’ll create
BookmarksPdf_output.pdf, with a top-level bookmark and an expanded parent containing a bookmark for each page.BookmarksPdf_outlines_output.pdf, with a bold red outline, nested children, a collapsed branch, and several destination modes.- Three blank Letter pages in each PDF. Open the PDF viewer's bookmarks panel to explore the navigation.

Example code
Add the following class to a console project that references the DynamicPDF Flow API. See the quick start for an overview. The class creates both PDFs and saves them to an existing output directory.
using System;
using System.IO;
using DynamicPDF.Flow;
namespace FluentExamples.Examples;
internal static class BookmarksPdf
{
public static void Run(string outputRoot)
{
BookMarkExample(outputRoot);
OutlineExample(outputRoot);
}
public static void BookMarkExample(string outputRoot)
{
var path = Path.Combine(
outputRoot, "BookmarksPdf_output.pdf");
DocumentBuilder.Create()
.Title("Bookmarks example")
.Pages(page => page
.Size(PageSize.Letter)
.Margins(50, LengthUnit.Point)
.Bookmark("Top level bookmark to page 1"))
.Pages(2, (page, index) => page
.Size(PageSize.Letter)
.Margins(50, LengthUnit.Point))
.Outlines(outlines => outlines
.Add("Parent Outline", parent => parent
.Expanded()
.Child("Bookmark to page 1", child => child
.Target(1, 50, 50))
.Child("Bookmark to page 2", child => child
.Target(2, 50, 50))
.Child("Bookmark to page 3", child => child
.Target(3, 50, 50))))
.Save(path);
Console.WriteLine($"Created {path}");
}
public static void OutlineExample(string outputRoot)
{
var path = Path.Combine(
outputRoot, "BookmarksPdf_outlines_output.pdf");
DocumentBuilder.Create()
.Title("Outlines example")
.Pages(3, (page, index) => page
.Size(PageSize.Letter)
.Margins(50, LengthUnit.Point))
.Outlines(outlines => outlines
.Add("Outline1", first => first
.Bold()
.Color("#ff0000")
.Expanded()
.Child("Outline1A", child => child
.TargetZoom(2, PdfPageZoom.FitPage)
.Expanded(false)
.Child("Outline1A1", item => item
.Target(2, 50, 50))
.Child("Outline1A2", item => item
.TargetZoom(
2, PdfPageZoom.FitHeight)))
.Child("Outline1B", child => child
.TargetZoom(2, PdfPageZoom.FitWidth)))
.Add("Outline2", second => second
.Target(3, 50, 350)
.Expanded()
.Child("Outline2A")))
.Save(path);
Console.WriteLine($"Created {path}");
}
}
Imports System
Imports System.IO
Imports DynamicPDF.Flow
Friend Module BookmarksPdf
Public Sub Run(outputRoot As String)
BookMarkExample(outputRoot)
OutlineExample(outputRoot)
End Sub
Public Sub BookMarkExample(outputRoot As String)
Dim outputPath = Path.Combine(
outputRoot, "BookmarksPdf_output.pdf")
DocumentBuilder.Create().
Title("Bookmarks example").
Pages(Sub(page) page.
Size(PageSize.Letter).
Margins(50, unit:=LengthUnit.Point).
Bookmark("Top level bookmark to page 1")).
Pages(2, Sub(page, index) page.
Size(PageSize.Letter).
Margins(50, unit:=LengthUnit.Point)).
Outlines(Sub(outlines) outlines.
Add("Parent Outline", Sub(parent) parent.
Expanded().
Child("Bookmark to page 1", Sub(child) child.
Target(1, 50, 50)).
Child("Bookmark to page 2", Sub(child) child.
Target(2, 50, 50)).
Child("Bookmark to page 3", Sub(child) child.
Target(3, 50, 50)))).
Save(outputPath)
Console.WriteLine($"Created {outputPath}")
End Sub
Public Sub OutlineExample(outputRoot As String)
Dim outputPath = Path.Combine(
outputRoot, "BookmarksPdf_outlines_output.pdf")
DocumentBuilder.Create().
Title("Outlines example").
Pages(3, Sub(page, index) page.
Size(PageSize.Letter).
Margins(50, unit:=LengthUnit.Point)).
Outlines(Sub(outlines) outlines.
Add("Outline1", Sub(first) first.
Bold().
Color("#ff0000").
Expanded().
Child("Outline1A", Sub(child) child.
TargetZoom(2, PdfPageZoom.FitPage).
Expanded(False).
Child("Outline1A1", Sub(item) item.
Target(2, 50, 50)).
Child("Outline1A2", Sub(item) item.
TargetZoom(
2, PdfPageZoom.FitHeight))).
Child("Outline1B", Sub(child) child.
TargetZoom(2, PdfPageZoom.FitWidth))).
Add("Outline2", Sub(second) second.
Target(3, 50, 350).
Expanded().
Child("Outline2A"))).
Save(outputPath)
Console.WriteLine($"Created {outputPath}")
End Sub
End Module
How it works
1. Choose the output paths
Run calls BookMarkExample and OutlineExample. Each method combines outputRoot with its own filename. Make sure the output directory exists. Saving overwrites an existing file with the same name.
2. Create the page bookmark and its outline hierarchy
BookMarkExample sets the document title before creating three Letter pages with 50-point margins. The first page's .Bookmark(...) adds the top-level bookmark at the start of the page body.
.Outlines(...) adds Parent Outline as an expanded grouping entry with three children. Each child's .Target(pageNumber, x, y) points to the corresponding page's upper-left content position. Page numbers are one-based, and the target coordinates are absolute points measured from the page's upper-left corner. The (50, 50) targets match the page margins.
3. Style the nested outlines
OutlineExample creates three more Letter pages. .Bold() and .Color("#ff0000") style Outline1, while .Child(...) builds its hierarchy. .Expanded() opens the parent branches initially; .Expanded(false) keeps Outline1A collapsed. Entries without a target, such as Outline2A, act as grouping entries.
4. Configure the destinations
| Outline | Destination |
|---|---|
Outline1A | Page 2, fit the whole page |
Outline1A1 | Page 2, absolute position (50, 50) |
Outline1A2 | Page 2, fit the page height |
Outline1B | Page 2, fit the page width |
Outline2 | Page 3, absolute position (50, 350) |
.TargetZoom(...) chooses a fit mode through PdfPageZoom. .Target(...) chooses a coordinate destination measured in points from the page's upper-left corner.
5. Save each PDF
.Save(path) writes each document through the Fluent builder. Console.WriteLine prints its output path. Bookmarks and outlines provide navigation; they do not add visible text to the blank pages.
Next steps
You can give an outline a page-and-coordinate target with .Target(page, x, y) or a page-and-zoom target with .TargetZoom(page, zoom). See OutlineTargetsPdf.cs for an example of coordinate targets and FitPage, FitWidth, and FitHeight zoom settings. See MoreBookmarkExamples.cs for more bookmark examples.
Add page content using Create a PDF, experiment with the outline labels and destinations, or browse all examples.