Comment ajouter et modifier des annotations PDF
Les annotations permettent aux utilisateurs d'ajouter des commentaires, des rappels ou des informations supplémentaires à des sections spécifiques du document. Ils améliorent la collaboration et la communication lors de l'utilisation des PDF, en permettant aux utilisateurs d'annoter, de commenter et de mettre en contexte le contenu partagé.
Commencez avec IronPDF!
Commencez à utiliser IronPDF dans votre projet dès aujourd'hui avec un essai gratuit.
Comment ajouter et modifier des annotations PDF
- Télécharger la bibliothèque C# pour les annotations PDF
- Chargement d'un document PDF existant ou création d'un nouveau document PDF
- Utiliser le
Ajouter
Méthode d'ajout d'annotations - Récupérer et modifier des annotations PDF
- Supprimer les annotations des documents PDF
Exemple d'ajout d'annotations
Les annotations PDF permettent d'ajouter des commentaires de type "notes autocollantes" aux pages PDF. La méthode Add
de la propriété Annotations permet d'ajouter des annotations de manière programmatique.
Conseils
: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
PDF avec une annotation
L'annotation dans le document PDF ci-dessus peut être visualisée avec le navigateur Chrome.
Exemple de récupération et de modification d'annotations
La récupération et l'édition d'annotations PDF améliorent la collaboration en renforçant la clarté, la précision et la convivialité. Accédez à la collection d'annotations par le biais de la propriété Annotations et mettez à jour les propriétés telles que Titre, Contenu, X, Y, etc. avec de nouvelles informations.
: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")
PDF avec une annotation éditée
L'annotation dans le document PDF ci-dessus peut être visualisée avec le navigateur Chrome.
Exemple de suppression d'annotation
Supprimez facilement les annotations inutiles ou obsolètes en utilisant les méthodes suivantes : RemoveAt
, RemoveAllAnnotationsForPage
, et Clear
.
- RemoveAt : Supprime une seule annotation avec l'index spécifié.
- RemoveAllAnnotationsForPage : Supprime toutes les annotations sur une page donnée.
- Effacer : Supprime toutes les annotations dans le document.
Supprimer une seule annotation
Pour supprimer une seule annotation, utilisez la méthode RemoveAt
avec l'index correspondant basé sur l'index de la collection d'annotations.
: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")
Suppression d'une seule annotation sur un PDF
Avant
Après
L'annotation dans le document PDF ci-dessus peut être visualisée avec le navigateur Chrome.
Supprimer toutes les annotations
Pour supprimer toutes les annotations d'une page particulière, utilisez la méthode RemoveAllAnnotationsForPage
et spécifiez l'index de la page. Si vous souhaitez supprimer toutes les annotations dans l'ensemble du document, il vous suffit d'appeler la méthode Clear
sur la propriété Annotations.
: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")