Add PDF Outline Bookmarks

A PDF outline, or bookmark, allows you to navigate to key pages of a PDF, similar to a Table of Contents. Including these in your C# project can be essential for usability and UX design.

Add Outline Bookmark
using IronPdf;

// Create a new PDF or edit an existing document.

PdfDocument Pdf = PdfDocument.FromFile("existing.pdf");

// Add a bookmark

Pdf.BookMarks.AddBookMarkAtEnd("NameOfBookmark",17,0)

// Add a sub-bookmark within the previous

Pdf.BookMarks.AddBookMarkAtEnd("NameOfSubBookmark",17,1)

//delete an old Bookmark

Pdf.BookMarks.RemoveBookMarkAt(0);
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",17,0) Pdf.BookMarks.AddBookMarkAtEnd("NameOfSubBookmark",17,1) Pdf.BookMarks.RemoveBookMarkAt(0)
Jump to Article
Extract and Search Text
PdfDocument PDF = PdfDocument.FromFile("file.pdf");

string AllText = PDF.ExtractAllText();

for (var index = 0; index < PDF.PageCount; index++) {

 int PageNumber = index + 1;

 string Text = PDF.ExtractTextFromPage(index);

//Search here!

}
Dim PDF As PdfDocument = PdfDocument.FromFile("file.pdf")

Dim AllText As String = PDF.ExtractAllText()

For index = 0 To PDF.PageCount - 1

 Dim PageNumber As Integer = index + 1

 Dim Text As String = PDF.ExtractTextFromPage(index)

'Search here!

Next index
Jump to Article
Try IronPDF free for development


Step 1

1. Use IronPDF for C#

To easily add outlines and bookmarks to your PDF, first you should install the IronPDF software library (free for development with this tutorial). You can access it through DLL download as well as learn more and install using the latest NuGet package. Open in Visual Studio and start the tutorial below.


 PM > Install-Package IronPdf


How to Tutorial

2. Add Outlines & Bookmarks

In Adobe Acrobat Reader, the outlines, or bookmarks are shown in the left sidebar.

IronPDF imports existing outlines from existing PDF documents and allows them to be removed, added, re-ordered, and edited.

Adding a bookmark with IronPDF is as simple as the following. First, install IronPDF as outlined in the previous steps. Then add the following code:


using IronPdf;

// Create a new PDF or edit an existing document.

PdfDocument Pdf = PdfDocument.FromFile("existing.pdf");

// Add a bookmark

Pdf.BookMarks.AddBookMarkAtEnd("NameOfBookmark",17,0)

// Add a sub-bookmark within the previous

Pdf.BookMarks.AddBookMarkAtEnd("NameOfSubBookmark",17,1)

//delete an old Bookmark

Pdf.BookMarks.RemoveBookMarkAt(0);
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",17,0) Pdf.BookMarks.AddBookMarkAtEnd("NameOfSubBookmark",17,1) Pdf.BookMarks.RemoveBookMarkAt(0)
VB   C#

3. Extract and Search Text & Images

Part of navigation may include searching for text, and is therefore relevant to outlines and bookmarks.

Let’s presume you have extracted text from a PDF document, and you still need to be able to search and find the extracted text. The finding is easy. The extraction of the heading tags, however, is trickier, as a PDF document contains no reference to the content it was generated from.

To extract text from a PDF document, make use of the ExtractTextFromPage method from the PDF document object along with the ExtractAllText method.

Here is a quick example on how to extract text from a PDF document:

PdfDocument PDF = PdfDocument.FromFile("file.pdf");

string AllText = PDF.ExtractAllText();

for (var index = 0; index < PDF.PageCount; index++) {

 int PageNumber = index + 1;

 string Text = PDF.ExtractTextFromPage(index);

//Search here!

}
Dim PDF As PdfDocument = PdfDocument.FromFile("file.pdf")

Dim AllText As String = PDF.ExtractAllText()

For index = 0 To PDF.PageCount - 1

 Dim PageNumber As Integer = index + 1

 Dim Text As String = PDF.ExtractTextFromPage(index)

'Search here!

Next index
VB   C#

Now you can add search text easily with the various string methods provided in .NET

As a bonus, to extract Images, all you would need to use is the ExtractImagesFromPage method from the PDF document, object along with the ExtractAllImages method. And there you go!