Delete bookmark from the PDF document in C#

PDF Bookmarks is widely used to help us locate and link to points that we want to go. Spire.PDF for .NET, a powerful PDF component, not only enables developers to add bookmarks, get bookmark information, but also helps us to remove the bookmarks that we want. This article will show you how to delete bookmark from the PDF document in C# easily.

First, check the PDF document with bookmarks.

Bookmark

Here comes to the steps of how to remove the bookmarks in C#.

  • Download Spire.PDF for .NET and install it correctly. The Spire.PDF installation is clean, professional and wrapped up in a MSI installer.
  • Add Spire.Pdf.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Pdf\Bin\NET4.0\ Spire.Pdf.dll".
  • Check the code snippet of how to delete the bookmarks. With Spire.PDF.NET, we can remove both the particular bookmark and remove all the bookmarks at one time.
//Create a new PDF document and load from the file.
PdfDocument document = new PdfDocument();
document.LoadFromFile(@"D:\Bookmark.pdf");

//remove the first bookmark
document.Bookmarks.RemoveAt(0);

//remove all bookmarks
document.Bookmarks.Clear();

//save the document to file.
document.SaveToFile("result.pdf");

Please check the effective screenshots:

Remove particular bookmark

Remove all Bookmarks