How to Add PDF Bookmarks and Outline
Including PDF outline, also known as bookmark, 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.
How to Add PDF Bookmarks and Outline
Install with NuGet
Install-Package IronPdf
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronPdf
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.
Install-Package IronPdf
Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip
Manually install into your project
Download DLLAdd 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.
Tips
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.
: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")
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")
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 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()
Please note
Before proceeding
Learn how to create Table of Content when generating PDF from HTML in the following article: "How to Add Table of Contents."