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>
Remarks
Supported Operations:
Related Resources:
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). |