Annotations
PDF annotations allow "sticky note"-like comments to be added to PDF pages. The IronPDF.PdfDocument.AddTextAnnotation
method and PdfDocument.TextAnnotation
class allow annotations to be added programmatically. Advanced text annotation features supported include coloring, sizing, opacity, icons, and editing.
How to Add PDF Annotation in .NET
- Install C# library to add annotation to PDF.
- Open an existing or generate a new PDF in .NET.
- Create a
TextAnnotation
class and customize properties. - Utilize the
AddTextAnnotation
method to add the newly created annotation to the PDF. - Export the modified PDF to the desired folder.
// This example demonstrates how to add a text annotation to a PDF using IronPDF in C#.
using IronPdf;
class Program
{
static void Main()
{
// Load an existing PDF document
var pdf = PdfDocument.FromFile("example.pdf");
// Create a text annotation
var annotation = new PdfDocument.TextAnnotation
{
PageNumber = 1, // Specify the page number to add the annotation
X = 100, // X coordinate on the page
Y = 150, // Y coordinate on the page
Text = "This is a sample annotation.", // Content of the annotation
Color = "Yellow", // Background color of the annotation
Icon = AnnotationIcon.Comment, // Icon style for the annotation
Opacity = 0.8 // Opacity of the annotation
};
// Add the annotation to the PDF
pdf.AddTextAnnotation(annotation);
// Save the modified PDF to a file
pdf.SaveAs("modified_example.pdf");
}
}
// This example demonstrates how to add a text annotation to a PDF using IronPDF in C#.
using IronPdf;
class Program
{
static void Main()
{
// Load an existing PDF document
var pdf = PdfDocument.FromFile("example.pdf");
// Create a text annotation
var annotation = new PdfDocument.TextAnnotation
{
PageNumber = 1, // Specify the page number to add the annotation
X = 100, // X coordinate on the page
Y = 150, // Y coordinate on the page
Text = "This is a sample annotation.", // Content of the annotation
Color = "Yellow", // Background color of the annotation
Icon = AnnotationIcon.Comment, // Icon style for the annotation
Opacity = 0.8 // Opacity of the annotation
};
// Add the annotation to the PDF
pdf.AddTextAnnotation(annotation);
// Save the modified PDF to a file
pdf.SaveAs("modified_example.pdf");
}
}
' This example demonstrates how to add a text annotation to a PDF using IronPDF in C#.
Imports IronPdf
Friend Class Program
Shared Sub Main()
' Load an existing PDF document
Dim pdf = PdfDocument.FromFile("example.pdf")
' Create a text annotation
Dim annotation = New PdfDocument.TextAnnotation With {
.PageNumber = 1,
.X = 100,
.Y = 150,
.Text = "This is a sample annotation.",
.Color = "Yellow",
.Icon = AnnotationIcon.Comment,
.Opacity = 0.8
}
' Add the annotation to the PDF
pdf.AddTextAnnotation(annotation)
' Save the modified PDF to a file
pdf.SaveAs("modified_example.pdf")
End Sub
End Class