[]
An annotation is used to mark or highlight texts, images and other visual elements on a page. Annotations can be text, image, shape, sound or even file attachments. The purpose of using annotation is to simply associate information or a note with an item on a page. A number of annotations can be displayed either in open or closed state. In the closed state, they appear on the page as a note, icon, or a box, depending on the annotation type. In the opened state, these annotations display the associated object such as a pop-up window containing associated text. For more information on annotations and its types, see PDF specification 1.7 (Section 12.5).
GcPdf offers a variety of standard annotation types, as listed below:
All the listed annotations have a dedicated class and properties in the GcPdf library which makes it easier to implement different annotations. GcPdf also allows you to specify various characteristics of annotation such as visibility, printing, etc. using Flags property that accepts the values from AnnotationFlags enum.
GcPdf allows you to add annotations to a page in the PDF document. These annotations reside in the Page object on which they are placed.
To add an annotation on a page:
Create an instance of class corresponding to annotation type you want to add to a page, for example, TextAnnotation class.
Call the Add method to add the annotation on the page.
var textAnnot = new TextAnnotation()
{
Contents = "This is an annotation in red color.",
Name = "Text Annotation",
Rect = new RectangleF(72, 72, 72 * 2, 72),
Color = Color.Red,
};
// Add the text annotation
page.Annotations.Add(textAnnot);
To get the annotations from a page:
Create an instance of the AnnotationCollection class.
Use the AnnotationCollection object to access the annotation by specifying its index.
// Get Annotation
AnnotationCollection acol = doc.Pages[0].Annotations;
// Display the property values
Console.WriteLine("Annotation Type: {0}", acol[0].Name);
To modify the annotation, you can set the properties of the type of annotation you used on a page. For instance, setting Contents property of AnnotationBase class and Color property of the TextAnnotation class modifies the existing content and color of the annotation.
// Modify annotation
textAnnot.Color = Color.BlueViolet;
textAnnot.Contents = "This is a Text annotation.";
To delete all the annotations from a page, use the Clear method. Apart from this, RemoveAt method can be used to remove a particular annotation by specifying its index value.
// Delete all annotations
page.Annotations.Clear();
// Delete a particular annotation
page.Annotations.RemoveAt(0);
For more information about how to implement annotations using GcPdf, see GcPdf sample browser.