How to Add PDF Bookmarks and Outline

Including PDF outlines, also known as bookmarks, in your C# project can greatly enhance usability and UX design. PDF outlines function as a navigation tool, allowing users to easily access key pages within the document, similar to a Table of Contents. By incorporating PDF outlines, you can provide a more intuitive and user-friendly experience for your document.

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer




Add Outlines & Bookmarks Example

In Adobe Acrobat Reader, outlines (also known as bookmarks) are displayed in the left sidebar, providing a convenient way to jump to key sections of the document.

With IronPDF, you have the capability to import PDF documents and perform various operations on existing outlines, such as adding, reordering, editing properties, and deleting bookmarks. This gives you full control over the organization and structure of your PDF files.

TipsAll the pages index follow zero-based indexing.

Add Single Layer of Bookmarks

Adding a bookmark in IronPDF is a straightforward process. You can use the AddBookmarkAtEnd method, which requires specifying the bookmark name and the corresponding page index. Below is an example code snippet:

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-single-layer-bookmark.cs
using IronPdf;

// Create a new PDF or edit an existing document.
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");

// Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);

// Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);

pdf.SaveAs("singleLayerBookmarks.pdf");
Imports IronPdf

' Create a new PDF or edit an existing document.
Private pdf As PdfDocument = PdfDocument.FromFile("existing.pdf")

' Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)

' Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)

pdf.SaveAs("singleLayerBookmarks.pdf")
$vbLabelText   $csharpLabel

Single-layer Bookmarks Document

Add Multiple Layers of Bookmarks

With IronPDF, you can add bookmarks in a tree structure, which is particularly useful for maintaining navigability in large PDF documents. This feature comes in handy when dealing with extensive collections of examination papers, sales reports, or receipt records from various dates and locations in a single PDF document.

The AddBookMarkAtEnd method returns an IPdfBookMark object, allowing you to add child bookmarks. For example, you can use Children.AddBookMarkAtStart("Date1", 0) or Children.AddBookMarkAtEnd("Date1", 0) to add child bookmarks to the "Examination" bookmark. The following code demonstrates this concept:

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-multi-layer-bookmark.cs
using IronPdf;

// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("examinationPaper.pdf");

// Assign IPdfBookMark object to a variable
var mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0);

// Add bookmark for days
var date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1);

// Add bookmark for type of test
var paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1);
paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3);
paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4);

// Add bookmark for days
var date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5);

// Add bookmark for type of test
var computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5);
computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6);
computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7);

pdf.SaveAs("multiLayerBookmarks.pdf");
Imports IronPdf

' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("examinationPaper.pdf")

' Assign IPdfBookMark object to a variable
Private mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0)

' Add bookmark for days
Private date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1)

' Add bookmark for type of test
Private paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1)
paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3)
paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4)

' Add bookmark for days
Dim date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5)

' Add bookmark for type of test
Dim computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5)
computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6)
computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7)

pdf.SaveAs("multiLayerBookmarks.pdf")
$vbLabelText   $csharpLabel

Multi-layer Bookmarks Document

Retrieve Bookmarks List

With IronPDF, you can easily retrieve and view the bookmarks in a PDF document. Navigating through the bookmark tree is straightforward and provides seamless access to different sections. Let's consider the multi-layer bookmarks document example above.

The "Examination" bookmark will have a Children property that points to the "Date1" and "Date2" bookmarks. The "Date1" bookmark, in turn, has a NextBookmark property that points to the "Date2" bookmark. Additionally, the "Date1" bookmark has a Children property that contains the "Paper" bookmark.

To retrieve all the bookmarks present in the opened PDF document, you can use the GetAllBookmarks method. This will provide you with a comprehensive list of all bookmarks, allowing you to further analyze and utilize the bookmark structure.

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-retrieve-bookmark.cs
using IronPdf;

// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");

// Retrieve bookmarks list
var mainBookmark = pdf.Bookmarks.GetAllBookmarks();
Imports IronPdf

' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("multiLayerBookmarks.pdf")

' Retrieve bookmarks list
Private mainBookmark = pdf.Bookmarks.GetAllBookmarks()
$vbLabelText   $csharpLabel

Please noteMerging two PDF documents that have bookmarks with identical names can lead to a disruption in the bookmark list.

WarningOnly bookmarks created from page index are supported. Bookmarks made from other parts or elements in PDF document will get the page index value set to -1.

Learn how to create a Table of Contents when generating PDF from HTML in the following article: "Creating a Table of Contents with IronPDF."

Ready to see what else you can do? Check out our tutorial page here: Organize PDFs

Frequently Asked Questions

How do I start using IronPDF for adding bookmarks in a PDF?

To start using IronPDF for adding bookmarks, download IronPDF from NuGet, load an existing PDF or render a new one, and use the `AddBookmarkAtEnd` method to add bookmarks to your document.

What is the role of bookmarks in a PDF document?

Bookmarks in a PDF document act as a navigational tool, allowing users to easily jump to key sections, similar to a Table of Contents, which enhances the document's usability.

How can I add multiple layers of bookmarks to a PDF?

With IronPDF, you can create multiple layers of bookmarks in a tree structure using the `AddBookMarkAtEnd` method, which is useful for organizing large documents with hierarchical content.

What is the process to retrieve bookmarks from a PDF using IronPDF?

You can retrieve bookmarks from a PDF by using IronPDF's `GetAllBookmarks` method, which provides a list of all bookmarks, facilitating easy navigation and analysis of the document.

Can I edit or delete bookmarks in a PDF with IronPDF?

Yes, IronPDF allows you to manage bookmarks by adding, reordering, editing properties, and deleting bookmarks, giving you full control over the PDF's organizational structure.

What should be considered when merging PDFs with bookmarks?

When merging PDF documents with bookmarks, ensure the bookmarks have unique names, as merging PDFs with identical bookmark names can disrupt the bookmark structure.

How can I create a Table of Contents in a PDF generated from HTML?

To create a Table of Contents in a PDF generated from HTML, refer to the article 'Creating a Table of Contents with IronPDF,' which provides detailed guidance on this process.

What happens if a bookmark is created from a non-page index element?

Bookmarks created from elements other than page index will have the page index value set to -1, as IronPDF supports bookmarks made directly from page indices only.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.