using IronPdf;
// Crea un nuevo PDF o carga y edita un documento existente.
var pdf = PdfDocument.FromFile("existing.pdf");
int pageIndex1 = 0;
int pageIndex2 = 1;
// Crear un objeto de anotación PDF en un índice de página especificado
var annotation1 = new IronPdf.Annotations.TextAnnotation(pageIndex1)
{
Title = "This is the major title 1",
Contents = "This is the long 'sticky note' comment 1st content...",
X = 150,
Y = 200,
Width = 200,
Height = 50,
Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
Opacity = 0.9,
Printable = false,
Hidden = false,
OpenByDefault = true,
ReadOnly = false,
Rotatable = true
};
var annotation2 = new IronPdf.Annotations.TextAnnotation(pageIndex2)
{
Title = "This is the major title 2",
Contents = "This is the long 'sticky note' comment 2nd content...",
X = 100,
Y = 150,
Width = 250,
Height = 150,
Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
Opacity = 0.9,
Printable = false,
Hidden = false,
OpenByDefault = true,
ReadOnly = false,
Rotatable = true
};
var annotation3 = new IronPdf.Annotations.TextAnnotation(pageIndex2)
{
Title = "This is the major title 3",
Contents = "This is the long 'sticky note' comment 3rd content...",
X = 200,
Y = 150,
Width = 150,
Height = 50,
Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
Opacity = 0.9,
Printable = false,
Hidden = false,
OpenByDefault = true,
ReadOnly = false,
Rotatable = true
};
// Añada la anotación "nota adhesiva" dentro de cualquier PDF nuevo o existente.
pdf.Annotations.Add(annotation1); // El índice de la anotación1 es 0.
pdf.Annotations.Add(annotation2); // El índice de la anotación2 es 1.
pdf.Annotations.Add(annotation3); // El índice de anotación3 es 2.
// Eliminar una única anotación con el índice especificado
pdf.Annotations.RemoveAt(1); // se elimina la anotación2, el índice de la anotación3 pasa a ser 1.
// Eliminar todas las anotaciones de una página determinada
pdf.Annotations.RemoveAllAnnotationsForPage(0); // eliminar todas las anotaciones de la página 1, el índice de la anotación3 pasa a ser 0.
// Editar una única anotación con el índice especificado
pdf.Annotations[0].Title = "new title for annotation 3";
pdf.Annotations[0].Contents = "This is new comment content of annotation 3";
// Eliminar todas las anotaciones del documento
pdf.Annotations.Clear();
pdf.SaveAs("existing.pdf");
Imports IronPdf
' Crea un nuevo PDF o carga y edita un documento existente.
Private pdf = PdfDocument.FromFile("existing.pdf")
Private pageIndex1 As Integer = 0
Private pageIndex2 As Integer = 1
' Crear un objeto de anotación PDF en un índice de página especificado
Private annotation1 = New IronPdf.Annotations.TextAnnotation(pageIndex1) With {
.Title = "This is the major title 1",
.Contents = "This is the long 'sticky note' comment 1st content...",
.X = 150,
.Y = 200,
.Width = 200,
.Height = 50,
.Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
.Opacity = 0.9,
.Printable = False,
.Hidden = False,
.OpenByDefault = True,
.ReadOnly = False,
.Rotatable = True
}
Private annotation2 = New IronPdf.Annotations.TextAnnotation(pageIndex2) With {
.Title = "This is the major title 2",
.Contents = "This is the long 'sticky note' comment 2nd content...",
.X = 100,
.Y = 150,
.Width = 250,
.Height = 150,
.Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
.Opacity = 0.9,
.Printable = False,
.Hidden = False,
.OpenByDefault = True,
.ReadOnly = False,
.Rotatable = True
}
Private annotation3 = New IronPdf.Annotations.TextAnnotation(pageIndex2) With {
.Title = "This is the major title 3",
.Contents = "This is the long 'sticky note' comment 3rd content...",
.X = 200,
.Y = 150,
.Width = 150,
.Height = 50,
.Icon = IronPdf.Annotations.TextAnnotation.AnnotationIcon.Help,
.Opacity = 0.9,
.Printable = False,
.Hidden = False,
.OpenByDefault = True,
.ReadOnly = False,
.Rotatable = True
}
' Añada la anotación "nota adhesiva" dentro de cualquier PDF nuevo o existente.
pdf.Annotations.Add(annotation1) ' El índice de la anotación1 es 0.
pdf.Annotations.Add(annotation2) ' El índice de la anotación2 es 1.
pdf.Annotations.Add(annotation3) ' El índice de anotación3 es 2.
' Eliminar una única anotación con el índice especificado
pdf.Annotations.RemoveAt(1) ' se elimina la anotación2, el índice de la anotación3 pasa a ser 1.
' Eliminar todas las anotaciones de una página determinada
pdf.Annotations.RemoveAllAnnotationsForPage(0) ' eliminar todas las anotaciones de la página 1, el índice de la anotación3 pasa a ser 0.
' Editar una única anotación con el índice especificado
pdf.Annotations(0).Title = "new title for annotation 3"
pdf.Annotations(0).Contents = "This is new comment content of annotation 3"
' Eliminar todas las anotaciones del documento
pdf.Annotations.Clear()
pdf.SaveAs("existing.pdf")