using IronPdf;
// Create a new PDF or load and edit an existing document.
var pdf = PdfDocument.FromFile("existing.pdf");
int pageIndex1 = 0;
int pageIndex2 = 1;
// Create a PDF annotation object on a specified page index
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,
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,
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,
Opacity = 0.9,
Printable = false,
Hidden = false,
OpenByDefault = true,
ReadOnly = false,
Rotatable = true
};
// Add the annotation "sticky note" within any new or existing PDF.
pdf.Annotations.Add(annotation1); // annotation1 index is 0.
pdf.Annotations.Add(annotation2); // annotation2 index is 1.
pdf.Annotations.Add(annotation3); // annotation3 index is 2.
// Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1); // annotation2 is removed, annotation3 index becomes 1.
// Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0); // remove all annotaion on page 1, annotation3 index becomes 0.
// Edit a single annotation with specified index
pdf.Annotations[0].Title = "new title for annotation 3";
pdf.Annotations[0].Contents = "This is new comment content of annotation 3";
// Remove all annotaions on the document
pdf.Annotations.Clear();
pdf.SaveAs("existing.pdf");
Imports IronPdf
' Create a new PDF or load and edit an existing document.
Private pdf = PdfDocument.FromFile("existing.pdf")
Private pageIndex1 As Integer = 0
Private pageIndex2 As Integer = 1
' Create a PDF annotation object on a specified page index
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,
.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,
.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,
.Opacity = 0.9,
.Printable = False,
.Hidden = False,
.OpenByDefault = True,
.ReadOnly = False,
.Rotatable = True
}
' Add the annotation "sticky note" within any new or existing PDF.
pdf.Annotations.Add(annotation1) ' annotation1 index is 0.
pdf.Annotations.Add(annotation2) ' annotation2 index is 1.
pdf.Annotations.Add(annotation3) ' annotation3 index is 2.
' Remove a single annotation with specified index
pdf.Annotations.RemoveAt(1) ' annotation2 is removed, annotation3 index becomes 1.
' Remove all annotaions on a specified page
pdf.Annotations.RemoveAllAnnotationsForPage(0) ' remove all annotaion on page 1, annotation3 index becomes 0.
' Edit a single annotation with specified index
pdf.Annotations(0).Title = "new title for annotation 3"
pdf.Annotations(0).Contents = "This is new comment content of annotation 3"
' Remove all annotaions on the document
pdf.Annotations.Clear()
pdf.SaveAs("existing.pdf")
Install-Package IronPdf
Annotations
Votre entreprise dépense trop en abonnements annuels pour la sécurité et la conformité des PDF. Pensez à IronSecureDoc, qui propose des solutions de gestion de services SaaS tels que la signature numérique, la rédaction, le cryptage et la protection, le tout pour un paiement unique. Explorer la documentation IronSecureDoc
Les annotations PDF permettent d'ajouter des commentaires similaires à des 'post-it' aux pages PDF. La méthode IronPdf.PdfDocument.AddTextAnnotation et la classe PdfDocument.TextAnnotation permettent d'ajouter des annotations par programmation. Les fonctionnalités avancées des annotations textuelles prises en charge incluent la coloration, la taille, l'opacité, les icônes et l'édition.
Comment ajouter des annotations PDF en .NET
Installer la bibliothèque C# pour ajouter des annotations au PDF.
Ouvrez un fichier PDF existant ou générez-en un nouveau dans .NET.
Créez une classe TextAnnotation et personnalisez ses propriétés.
Utilisez la méthode AddTextAnnotation pour ajouter l'annotation nouvellement créée au PDF.
Votre clé d'essai devrait être dans l'e-mail. Si elle ne l'est pas, veuillez contacter support@ironsoftware.com
Rejoignez les millions d'ingénieurs qui ont essayé IronPDF
Votre clé d'essai devrait être dans l'e-mail. Si elle ne l'est pas, veuillez contacter support@ironsoftware.com
Parlez à l'Équipe de Vente
Réservez une Consultation sans Engagement
Comment pouvons-nous vous aider :
Consultez votre flux de travail et vos points de douleur
Voyez comment d'autres entreprises répondent à leurs besoins en matière de documents .NET
Toutes vos questions reçoivent une réponse pour vous assurer d'avoir toutes les informations nécessaires. (Aucun engagement de quelque nature que ce soit.)
Obtenez un devis personnalisé pour les besoins de votre projet