Class PdfAnnotationCollection
Manages the collection of annotations (sticky notes, comments) in a PDF document. Supports adding, removing, and iterating through annotations across all pages.
Access via Annotations property. Changes to the collection are automatically synchronized with the PDF document.
Example - Work with annotations:
var pdf = PdfDocument.FromFile("document.pdf");
// Add annotation to first page:
var note = new TextAnnotation(0)
{
Title = "Review Note",
Contents = "Please verify this section",
X = 100,
Y = 700
};
pdf.Annotations.Add(note);
// List all annotations:
foreach (var annotation in pdf.Annotations)
Console.WriteLine($"Page {annotation.PageIndex}: {annotation.Contents}");
// Remove annotations from page 2:
pdf.Annotations.RemoveAllAnnotationsForPage(1);
// Clear all annotations:
pdf.Annotations.Clear();
pdf.SaveAs("annotated.pdf");
Inheritance
Namespace: IronPdf.Annotations
Assembly: IronPdf.dll
Syntax
public class PdfAnnotationCollection : ObservableCollection<IAnnotation>
PDF annotations in IronPDF is handled through PdfAnnotationCollection. It manages the collection of annotations (sticky notes, comments) in a PDF document.
PdfAnnotationCollection matters when an application needs to configure or invoke PDF annotations from C# code. The class encapsulates the related options and behavior in a single object that is set up once and reused across render or processing calls. Typical scenarios include batch generation pipelines, templated document workflows, and integration with existing C# document services.
To use PdfAnnotationCollection, instantiate or obtain it from the relevant entry point in the IronPDF C# API. Key methods include ClearItems, RemoveAllAnnotationsForPage. Assign options or invoke methods on the instance to configure or perform the operation. The access PDF DOM object covers typical usage in C# end to end.
using IronPdf;
// Obtain PdfAnnotationCollection from the relevant entry point in the IronPDF API
void Configure(PdfAnnotationCollection instance)
{
instance.ClearItems();
}For the broader workflow, see the add copy delete pages PDF guide in the IronPDF C# documentation. For broader context, the PDF annotations portion of the IronPDF C# API contains related types that work with PdfAnnotationCollection directly. PdfAnnotationCollection instances inherit additional members from ObservableCollection<IAnnotation> that may be relevant in advanced scenarios. In application code, treat PdfAnnotationCollection as a configured object that is constructed once and reused across operations rather than instantiated per call. Configuration is generally idempotent: assigning the same property value twice has the same effect as assigning it once. For diagnostic purposes, inspect the relevant PdfAnnotationCollection property after each operation to confirm the configured state. See the constructors, properties, and methods tables below for the complete API surface of PdfAnnotationCollection. Application code typically obtains or instantiates a single PdfAnnotationCollection and shares it across multiple IronPDF operations rather than recreating it per call.
Methods
ClearItems()
Override Clear() with Interop RemoveAnnotation() through every annotations in the collection.
Declaration
protected override void ClearItems()
RemoveAllAnnotationsForPage(Int32)
Removes all annotations from a specific page of the PDF document.
Example:
// Remove annotations from page 3 (index 2):
pdf.Annotations.RemoveAllAnnotationsForPage(2);
// Remove annotations from all pages:
for (int i = 0; i < pdf.PageCount; i++)
pdf.Annotations.RemoveAllAnnotationsForPage(i);
Declaration
public void RemoveAllAnnotationsForPage(int pageIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | pageIndex | Zero-based page index (Page 1 = index 0). |