Modify Annotations in your PDF
Contents
[
Hide
]
Modify annotation
ModifyAnnotations method allows you to change basic attributes of an annotation i.e. Subject, Modified date, Author, Annotation color, and Open flag. You can also set Author directly by using ModifyAnnotations method. This class also provides two overloaded methods to delete annotations. The first method called DeleteAnnotations deletes all the annotations from a PDF file.
For example, in the following code, consider changing the author in our annotation using ModifyAnnotationsAuthor.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ModifyAnnotationsAuthor()
{
// The path to the documents directory
string dataDir = RunExamples.GetDataDir_AsposePdf();
// Create PdfAnnotationEditor
using (var annotationEditor = new Aspose.Pdf.Facades.PdfAnnotationEditor())
{
// Bind PDF document
annotationEditor.BindPdf(dataDir + "input.pdf");
// Modify annotations author
annotationEditor.ModifyAnnotationsAuthor(1, 2, "Aspose User", "Aspose.PDF user");
// Save document
annotationEditor.Save(dataDir + "ModifyAnnotationsAuthor_out.pdf");
}
}
The second method allows you to delete all the annotations of a specified type.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ModifyAnnotations()
{
// The path to the documents directory
string dataDir = RunExamples.GetDataDir_AsposePdf();
// Open document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Create PdfAnnotationEditor
using (var annotationEditor = new Aspose.Pdf.Facades.PdfAnnotationEditor())
{
// Bind PDF document
annotationEditor.BindPdf(document);
// Create a new object of type Annotation to modify annotation attributes
var defaultAppearance = new Aspose.Pdf.Annotations.DefaultAppearance();
var annotation = new Aspose.Pdf.Annotations.FreeTextAnnotation(
document.Pages[1],
new Aspose.Pdf.Rectangle(1, 1, 1, 1),
defaultAppearance)
{
// Set new annotation attributees
Title = "Aspose.PDF Demo User",
Subject = "Technical Article"
};
// Modify annotations in the PDF file
annotationEditor.ModifyAnnotations(1, 1, annotation);
// Save document
annotationEditor.Save(dataDir + "ModifyAnnotations_out.pdf");
}
}
}
See also
Try to compare and find a way to work with annotations that suits you. Lets learn PDF Annotations section.