How to create structured bookmarks in Visual Studio C# programming.

PDF bookmarks are a handy and necessary tool when it comes to reading PDF files. It's interactive index that can instantly transport the reader to certain pages, sections, individual elements within the documents, and even external documents or media files.

Bookmarks allow users to quickly skip to other locations in the PDF, to navigate through the pages, and to get a quick glance at the PDF content similar as the quick jump to the webpage desired section.

.NET PDF bookmark creator library allows developers to insert and add outline to the PDF document. For the further needs, you can merge and split PDF with bookmarks. Here, we will introduce you how to add bookmark to PDF using C# code.

// Create a new PDF document.
var document = new PdfDocument();
// Create the first page.
var page = document.AddPage();

int pageIndex = 1;
string text = "Page " + pageIndex++.ToString();

// Create a font.
var font = new XFont("Times New Roman", 16);

// Get graphics of current page
var g = XGraphics.FromPdfPage(page);
g.DrawString(text, font, XBrushes.Black, 100, 100, XStringFormats.Center);

// Create the root bookmark. You can set the style and the color.
PdfOutline outline = document.Outlines.Add("Level 1", page, true, PdfOutlineStyle.Bold, XColors.Red);

// Create some more pages and bookmarks
for (int i = 1; i < 4; i++)
    page = document.AddPage();
    g = XGraphics.FromPdfPage(page);

    text = "Page " + pageIndex++.ToString();
    g.DrawString(text, font, XBrushes.Black, 100, 100, XStringFormats.Center);

    string bookmarkTitle = "Level 2-" + i.ToString();
    // Create a sub bookmark.
    outline.Outlines.Add(bookmarkTitle, page, true);               
// Save and show the document           

More PDF tutorial