PM > Install-Package XDoc.PDF

How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Bookmark Library
How to add, get, update, remove PDF bookmark & outline using c# in wpf, winform, asp.net


Empower Your C# Project with Rapid PDF Internal Navigation Via Bookmark and Outline in .NET Program











In this tutorial, you learn how to manage PDF bookmarks using C#.

  • Get PDF bookmarks
  • Add new PDF bookmark
  • Update PDF bookmark
  • Remove bookmarks
  • Create PDF from Word with bookmarks
  • Split PDF document by bookmarks

How to manage PDF bookmarks using C#

  1. Download XDoc.PDF Bookmark/Outline C# library
  2. Install C# library to manage PDF document bookmarks
  3. Step by Step Tutorial


























  • An advanced PDF SDK able to edit PDF bookmark in Visual C# .NET console application
  • Free trial library and components for navigate PDF with bookmark in C# .NET WinForms and ASP.NET program
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • C# demo code for editing PDF bookmarks in Visual Studio .NET class
  • Help to add or insert bookmark and outline into PDF file in .NET framework
  • Ability to remove and delete bookmark and outline from PDF document
  • Merge and split PDF file with bookmark
  • Save PDF file with bookmark open


RasterEdge XDoc.PDF SDK package provides PDF file navigation features for your C# project. On this C# tutorial, you will learn how to retrieve, edit and update PDF bookmark and outline.







Read, get PDF bookmarks using C#


Please directly copy and paste C# demo code below to your project to retrieve PDF document bookmarks.



String inputFilePath = Program.RootPath + "\\" + "2.pdf";
PDFDocument doc = new PDFDocument(inputFilePath); 
REOutline outline = doc.GetOutline();
foreach (REEntry entry in outline.Entry)
{
    Console.WriteLine("Page:     " + entry.GetPageIndex());
    Console.WriteLine("Level:    " + entry.GetLevel());
    Console.WriteLine("Position: " + entry.GetLocation());
    Console.WriteLine("Text:     " + entry.GetText());
}




Add PDF bookmarks using c#


String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Output_Outline.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

//  initial a new outline object
REOutline outline = new REOutline();

//  create 1st entry: Level = 1; Location: page index 0, y = 50
OutLine entryChapter1 = new OutLine("Chapter 1: *******", 1, 0, 50);
//  add 1st entry to outline
outline.Entry.Add(entryChapter1);

//  create 1st entry's child entries
//  create 1st child entry: Level = 2; Location: page index 1, y = 0
OutLine entryChapter11 = new OutLine("###### #### #### #### ###", 2, 1, 0);
//  connect this entry to the parent entry
entryChapter11.SetParentREEntry(entryChapter1);
//  add 1st child of 1st entry to outline
outline.Entry.Add(entryChapter11);

//  create 2nd child entry: Level = 2; Location: page index 2, y = 0
OutLine entryChapter12 = new OutLine("## ## ## ## ## #### ###", 2, 2, 0);
//  connect this entry to the parent entry
entryChapter12.SetParentREEntry(entryChapter1);
//  add 2nd child of 1st entry to outline
outline.Entry.Add(entryChapter12);

//  create 2nd entry: Level = 1; Location: page index 3, y = 100
OutLine entryChapter2 = new OutLine("Chapter 2: ******* ****", 1, 3, 100);
//  add 2nd entry to outline
outline.Entry.Add(entryChapter2);

//  create 3rd entry: Level = 1; Location: page index 5, y = 200
OutLine entryChapter3 = new OutLine("Chapter 3: **** **** ***", 1, 5, 200);
//  add 3rd entry to outline
outline.Entry.Add(entryChapter3);

//  create 3rd entry's child entries
//  create 1st child entry: Level = 2; Location: page index 9, y = 0
OutLine entryChapter31 = new OutLine("# #### ###", 2, 9, 0);
//  connect this entry to the parent entry
entryChapter31.SetParentREEntry(entryChapter3);
//  add 1st child of 3rd entry to outline
outline.Entry.Add(entryChapter31);

//  create a child entry for the 1st child entry of the 3rd entry
//  create entry: Level = 3; Location: page index 9, y = 500
OutLine entryChapter311 = new OutLine("???? ???? ??? ???", 3, 9, 500);
//  connect this entry to the parent entry
entryChapter311.SetParentREEntry(entryChapter31);
//  add 1st child of 3rd entry to outline
outline.Entry.Add(entryChapter311);

//  create 4th entry: Level = 1; Location: page index 10, y = 0
OutLine entryChapter4 = new OutLine("Chapter 4: ******* ** ** **** ***", 1, 10, 0);
//  add 4th entry to outline
outline.Entry.Add(entryChapter4);

//  create 5th entry: Level = 1; Location: page index 20, y = 0
OutLine entryChapter5 = new OutLine("Chapter 5: * ** **** **** ****", 1, 20, 0);
//  add 5th entry to outline
outline.Entry.Add(entryChapter5);

//  update the new outline
doc.SetOutline(outline);

doc.Save(outputFilePath);






Remove bookmarks from PDF document in C# application


To remove, delete all bookmarks from a PDF document, you call method SetOutline(null).

String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Output_Outline.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

//  remove all bookmarks
doc.SetOutline(null);

doc.Save(outputFilePath);





Create PDF from Word document with bookmarks using C# in ASP.NET, Windows app


When you convert Microsoft Word (.docx) to PDF file, you can generate PDF bookmarks from Word document heading content or bookmarks.

There are four options for OutlineMode:


  1. None: Do not create any outline entry.
  2. ByOutlineLevel: Create outline entries by paragraph's outline level.
  3. ByHeading: Create outline entries by paragraph's style IDs (heading styles).
  4. ByBookmark: Create outline entries by bookmarks.


You can view more features to convert Word to PDF file using C#.



String inputFilePath = @"C:\1.docx");
String outputFilePath = @"C:\output.pdf");

DOCXDocument doc = new DOCXDocument(inputFilePath);
//  Set strategy used to create outline entries for the document.
//  Default: OutlineMode.ByOutlineLevel
doc.OutlineSetting.Mode = OutlineMode.ByHeading;
//  Set the maximum level of entires in the outline.
//  Valid range: 1 ~ 9; default value: 3
doc.OutlineSetting.MaxLevel = 2;

//  Convert DOCX document to PDF file.
doc.ConvertToDocument(DocumentType.PDF, outputFilePath);






Split PDF file by bookmark using C# in ASP.NET, Windows application


When you separate a PDF document into multiple files, you can split PDF by bookmarks. You will also get more methods to split PDF document using C# here.

        #region split pdf file by top level bookmarks
        internal static void splitPdfFileByBookmarks()
        {
            String inputFilePath = @"C:\2.pdf";

            //  set split option
            SplitOptions options = new SplitOptions(SplitMode.ByBookMark);
            //  set output option
            SplitOutputOptions outputOps = new SplitOutputOptions();
            outputOps.OutputFolder = @"C:\output\";
            outputOps.Mode = 2;
            outputOps.Label = @"Part";
            outputOps.Separator = '_';
            //  split a PDF file with options
            PDFDocument.SplitDocument(inputFilePath, options, outputOps);
        }
        #endregion









Common Asked Questions

What is the purpose of Bookmarks in PDF?

In a PDF reader software, you can use click a bookmark to jump to a destination in the PDF document. You can use PDF editor software (Acrobat Pro or Foxit) to manage bookmarks. Using C# PDF library, you can quickly create new bookmarks, modify or delete existing bookmarks on the PDF document using C# in ASP.NET Core MVC web applications.

How do I create a bookmark in a PDF?

You need an installed PDF editor software to create a bookmark in a PDF document. You can also use C# PDF library to create new bookmarks in PDF document in Visual Studio .NET projects.

How do I create a nested bookmark in PDF?

You can create two levels of bookmarks in PDF document. Using Acrobat, you create a standard bookmark, then drag it under another bookmark to create a sub level bookmark. Using XDoc.PDF C# library, you can freely create multiple bookmarks with one or two levels in your C# ASP.NET, WinForms, WPF web and Windows applications.

Where is the bookmark panel in PDF?

Select the bookmarks icon from the left navigation pane in Acrobat. RasterEdge EdgePDF is an ASP.NET PDF Viewer and Editor library, and you can find the bookmarks icon from the left navigation pane in web browser.

What are the different types of Bookmarks in PDF?

There are two types of PDF bookmark. One is a normal bookmark to navigate to a set destination. The second bookmark is tagged bookmark, which use the underlying structural information of the document elements, for example heading levels. Using C# PDF library, you will easily create, edit, remove bookmarks on a PDF document in your C# asp.net, web and Windows apps.

What is the difference between Bookmarks and hyperlinks?

In PDF document, a bookmark will lead you to a destination inside the same PDF document. A hyperlink in a PDF document may lead you to a place in the same PDF document, or navigate you to a webpage. Using PDF C# SDK API, you will easily create, edit both bookmarks and hyperlinks on the PDF document in your C# ASP.NET apps.

How do I change the bookmarks on a PDF?

Open the PDF document using Acrobar Pro, in bookmarks pane, select and double-click the bookmark which you need to rename, update desktination. You can also build an online web application using RasterEdge EdgePDF ASP.NET PDF Editor web library. EdgePDF empower your ASP.NET web app with online PDF document viewing and editing features in web browser.

Can you remove Bookmarks from a PDF?

You can use a PDF editor application to remove the bookmarks from a PDF document. Using C# PDF component, you can easily remove one or all of the bookmarks from a PDF document in C# ASP.NET, MVC, Blazor, WinForms, web and desktop apps.