Get, create or edit outlines (bookmarks) in C# and VB.NET

With GemBox.Pdf, you can get, create or edit PDF document outlines (bookmarks) in your C# or VB.NET application.

The following example shows how you can remove existing PdfDocument.Outlines and create new ones in a PDF document.

PDF outlines created with GemBox.Pdf C#/VB.NET library
Screenshot of PDF outlines created with GemBox.Pdf library
Upload your file (Drag file here)
using System;
using GemBox.Pdf;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = PdfDocument.Load("%InputFileName%"))
        {
            // Remove all bookmarks.
            document.Outlines.Clear();

            // Get the number of pages.
            int numberOfPages = document.Pages.Count;

            for (int i = 0; i < numberOfPages; i += 10)
            {
                // Add a new outline item (bookmark) at the end of the document outline collection.
                var bookmark = document.Outlines.AddLast(string.Format("PAGES {0}-{1}", i + 1, Math.Min(i + 10, numberOfPages)));

                // Set the explicit destination on the new outline item (bookmark).
                bookmark.SetDestination(document.Pages[i], PdfDestinationViewType.FitRectangle, 0, 0, 100, 100);

                for (int j = 0; j < Math.Min(10, numberOfPages - i); j++)
                    // Add a new outline item (bookmark) at the end of parent outline item (bookmark) and set the explicit destination.
                    bookmark.Outlines.AddLast(string.Format("PAGE {0}", i + j + 1)).SetDestination(document.Pages[i + j], PdfDestinationViewType.FitPage);
            }

            document.PageMode = PdfPageMode.UseOutlines;

            document.Save("Outlines.pdf");
        }
    }
}
Imports System
Imports GemBox.Pdf

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using document = PdfDocument.Load("%InputFileName%")

            ' Remove all bookmarks.
            document.Outlines.Clear()

            ' Get the number of pages.
            Dim numberOfPages As Integer = document.Pages.Count

            For i As Integer = 0 To numberOfPages - 1 Step 10

                ' Add a new outline item (bookmark) at the end of the document outline collection.
                Dim bookmark = document.Outlines.AddLast(String.Format("PAGES {0}-{1}", i + 1, Math.Min(i + 10, numberOfPages)))

                ' Set the explicit destination on the New outline item (bookmark).
                bookmark.SetDestination(document.Pages(i), PdfDestinationViewType.FitRectangle, 0, 0, 100, 100)

                For j As Integer = 0 To Math.Min(10, numberOfPages - i) - 1
                    ' Add a new outline item (bookmark) at the end of parent outline item (bookmark) and set the explicit destination.
                    bookmark.Outlines.AddLast(String.Format("PAGE {0}", i + j + 1)).SetDestination(document.Pages(i + j), PdfDestinationViewType.FitPage)
                Next
            Next

            document.PageMode = PdfPageMode.UseOutlines

            document.Save("Outlines.pdf")
        End Using
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Pdf yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.