Cómo agregar y editar anotaciones PDF en C#

How to Add and Edit PDF Annotations

This article was translated from English: Does it need improvement?
Translated
View the article in English

Annotations allow users to add comments, reminders, or additional information to specific sections of the document. They enhance collaboration and communication in working with PDFs, enabling users to annotate, comment on, and provide context for shared content.

Quickstart: Add Annotations to PDFs Using IronPDF

This quick guide demonstrates how to effortlessly add text annotations to a PDF document using IronPDF in C#. With just a few lines of code, developers can enhance their PDFs by incorporating comments or notes, increasing document interactivity and collaboration. Start by loading your PDF and using the AddTextAnnotation method to insert annotations swiftly.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    PdfDocument.FromFile("input.pdf")
        .Annotations.Add(new TextAnnotation(0) { Title="Note", Contents="Review this section.", X=50, Y=700 })
        .SaveAs("annotated.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Add Annotations Example

PDF annotations allow the addition of "sticky note"-like comments to PDF pages. By using the Add method of the Annotations property, annotations can be programmatically added.

ConsejosAll page indexes follow zero-based indexing.

:path=/static-assets/pdf/content-code-examples/how-to/annotation-add-annotation.cs
using IronPdf;
using IronPdf.Annotations;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Annotation</h1>");

// Create a PDF annotation object on a specified page index
TextAnnotation annotation = new TextAnnotation(0)
{
    Title = "This is the title",
    Contents = "This is the long 'sticky note' comment content...",
    X = 50,
    Y = 700,
};

// Add the annotation
pdf.Annotations.Add(annotation);
pdf.SaveAs("annotation.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

PDF with an Annotation

The annotation in the PDF document above can be viewed with the Chrome browser.


Retrieve and Edit Annotations Example

Retrieving and editing PDF annotations improves collaboration by enhancing clarity, accuracy, and usability. Access the annotation collection through the Annotations property and update properties such as Title, Contents, X, Y, and more with new information.

:path=/static-assets/pdf/content-code-examples/how-to/annotation-edit-annotation.cs
using IronPdf;
using IronPdf.Annotations;
using System.Linq;

PdfDocument pdf = PdfDocument.FromFile("annotation.pdf");

// Retrieve annotation collection
PdfAnnotationCollection annotationCollection = pdf.Annotations;

// Select the first annotation
TextAnnotation annotation = (TextAnnotation)annotationCollection.First();

// Edit annotation
annotation.Title = "New title";
annotation.Contents = "New content...";
annotation.X = 150;
annotation.Y = 800;

pdf.SaveAs("editedAnnotation.pdf");
Imports IronPdf
Imports IronPdf.Annotations
Imports System.Linq

Private pdf As PdfDocument = PdfDocument.FromFile("annotation.pdf")

' Retrieve annotation collection
Private annotationCollection As PdfAnnotationCollection = pdf.Annotations

' Select the first annotation
Private annotation As TextAnnotation = CType(annotationCollection.First(), TextAnnotation)

' Edit annotation
annotation.Title = "New title"
annotation.Contents = "New content..."
annotation.X = 150
annotation.Y = 800

pdf.SaveAs("editedAnnotation.pdf")
$vbLabelText   $csharpLabel

PDF with an Edited Annotation

The annotation in the PDF document above can be viewed with the Chrome browser.


Remove Annotation Example

Easily remove unnecessary or outdated annotations using the following methods: RemoveAt, RemoveAllAnnotationsForPage, and Clear.

  • RemoveAt: Remove a single annotation with a specified index.
  • RemoveAllAnnotationsForPage: Remove all annotations on a specified page.
  • Clear: Remove all annotations in the document.

Remove a Single Annotation

To remove a single annotation, use the RemoveAt method with the corresponding index based on the annotation collection index.

:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-single-annotation.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");

// Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1);

pdf.SaveAs("removeSingleAnnotation.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")

' Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1)

pdf.SaveAs("removeSingleAnnotation.pdf")
$vbLabelText   $csharpLabel

Removed a Single Annotation on PDF

The annotation in the PDF document above can be viewed with the Chrome browser.

Remove All Annotations

To remove all annotations on a particular page, use the RemoveAllAnnotationsForPage method and specify the page index. If you want to remove all annotations in the entire document, simply call the Clear method on the Annotations property.

:path=/static-assets/pdf/content-code-examples/how-to/annotation-remove-all-annotation.cs
using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("multipleAnnotation.pdf");

// Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0);

// Remove all annotaions on the document
pdf.Annotations.Clear();

pdf.SaveAs("removeAllAnnotation.pdf");
Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("multipleAnnotation.pdf")

' Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0)

' Remove all annotaions on the document
pdf.Annotations.Clear()

pdf.SaveAs("removeAllAnnotation.pdf")
$vbLabelText   $csharpLabel

Ready to see what else you can do? Check out our tutorial page here: Edit PDFs

Preguntas Frecuentes

¿Cómo puedo agregar anotaciones a un PDF en C#?

Puede agregar anotaciones a un PDF en C# usando IronPDF. Primero, descargue la biblioteca C# para anotaciones en PDF. Cargue un documento PDF existente o cree uno nuevo, luego use el método Add de la propiedad Annotations para insertar comentarios o notas.

¿Cómo edito las anotaciones existentes en un PDF usando C#?

Para editar anotaciones existentes en un PDF usando C#, acceda a la colección de anotaciones a través de la propiedad Annotations de IronPDF. Actualice las propiedades como Título, Contenido, X e Y con nueva información para modificar las anotaciones.

¿Cuál es el proceso para eliminar anotaciones de un PDF usando C#?

Puede eliminar anotaciones de un PDF usando IronPDF empleando métodos como RemoveAt para eliminar una anotación específica, RemoveAllAnnotationsForPage para borrar todas las anotaciones de una página o Clear para eliminar todas las anotaciones del documento.

¿Puedo ver las anotaciones del PDF en un navegador web?

Sí, las anotaciones agregadas a los documentos PDF usando IronPDF pueden verse en navegadores web como Chrome.

¿Cuáles son los beneficios de agregar anotaciones a documentos PDF?

Agregar anotaciones a documentos PDF con IronPDF mejora la colaboración al permitir a los usuarios agregar comentarios, recordatorios o información adicional, mejorando la comunicación y el contexto para el contenido compartido.

¿Cómo puedo encontrar documentación para servicios de firma digital y encriptación?

La documentación para servicios de firma digital, redacción, encriptación y protección se puede encontrar en la página de documentación oficial de IronSecureDoc: https://ironsoftware.com/enterprise/securedoc/docs/.

¿Qué métodos de C# están disponibles para gestionar anotaciones en PDF?

IronPDF ofrece varios métodos de C# para gestionar anotaciones en PDF, incluidos Add para agregar, RemoveAt para eliminar anotaciones específicas, y Clear para borrar todas las anotaciones.

¿IronPDF es totalmente compatible con .NET 10 al trabajar con anotaciones?

Sí. IronPDF es totalmente compatible con .NET 10 (por diseño) y admite operaciones de anotación (agregar, editar, eliminar) de forma normal en proyectos .NET 10 sin necesidad de soluciones alternativas especiales.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado