Delete Annotation from PDF files in C#

Text annotation is often used in PDF file to show readers the extra information of the item. By using Spire.PDF you can not only add a new annotation, edit an existing annotation, but also delete annotations from PDF file. In this article, we will introduce you how to delete a particular annotation and delete all the annotation at one time.

First, check the PDF document with annotations.

Delete Annotation from PDF files in C#

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 annotations. With Spire.PDF.NET, we can remove both the particular annotation and remove all the annotations.

The code snippet of remove the first annotation from PDF file:

PdfDocument document = new PdfDocument();
//load the pdf file
document.LoadFromFile("E-iceblue.pdf");

//remove the first annotation
document.Pages[0].Annotations.RemoveAt(1);

document.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

The effective screenshot of remove the first annotation:

Delete Annotation from PDF files in C#

The code snippet of remove all annotations from PDF file:

PdfDocument document = new PdfDocument();
//load the pdf file
document.LoadFromFile("E-iceblue.pdf");

//remove all annotations
document.Pages[0].Annotations.Clear();

document.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

The effective screenshot of remove all the annotations:

Delete Annotation from PDF files in C#