This sample shows how to build PDF document's outline (also known as "bookmarks") using PdfOutlineItem.AddChild method.

Docotic.Pdf library provides methods and properties to manipulate document's outline. You can set PdfDocument.PageMode to a PdfPageMode.UseOutlines value to instruct a PDF viewer application to show "Bookmarks" panel when your document is opened.

PdfDocument.OutlineRoot property provides access to document's outline root. Value of this property is a PdfOutlineItem object. All outline items are instances of this class. Please use PdfOutlineItem methods and properties to access or setup outline items.

You can use PdfOutlineItem.AddChild method to add child items to an outline item. Second parameter for AddChild method is an index of page to associate with added child outline item.

using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
    public static class Outline
        public static void Main()
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit
            // for more information.

            string pathToFile = "Outline.pdf";

            using (PdfDocument pdf = new PdfDocument())
                pdf.PageMode = PdfPageMode.UseOutlines;


                for (int i = 0; i < pdf.PageCount; ++i)
                    PdfCanvas canvas = pdf.Pages[i].Canvas;
                    canvas.DrawString(260, 50, "Page " + (i + 1).ToString());

                PdfOutlineItem root = pdf.OutlineRoot;
                PdfOutlineItem outlineForPage1 = root.AddChild("Page 1", 0);
                PdfOutlineItem outlineForPage2 = root.AddChild("Page 2", 1);
                PdfOutlineItem childOutlineForPage3 = outlineForPage2.AddChild("Page 3", 2);


Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Outline
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit
            ' for more information.

            Dim pathToFile As String = "Outline.pdf"

            Using pdf As New PdfDocument()
                pdf.PageMode = PdfPageMode.UseOutlines


                For i As Integer = 0 To pdf.PageCount - 1
                    Dim canvas As PdfCanvas = pdf.Pages(i).Canvas
                    canvas.DrawString(260, 50, "Page " + (i + 1).ToString())

                Dim root As PdfOutlineItem = pdf.OutlineRoot
                Dim outlineForPage1 As PdfOutlineItem = root.AddChild("Page 1", 0)
                Dim outlineForPage2 As PdfOutlineItem = root.AddChild("Page 2", 1)
                Dim childOutlineForPage3 As PdfOutlineItem = outlineForPage2.AddChild("Page 3", 2)

            End Using

        End Sub
    End Class
End Namespace