Document Solutions for PDF
Features / Annotations
In This Topic
    In This Topic

    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).

    DsPdf offers a variety of standard annotation types. It is listed in the topic Annotation Types.

    All the listed annotations have a dedicated class and properties in the DsPdf library which makes it easier to implement different annotations. DsPdf also allows you to specify various characteristics of annotation such as visibility, printing, etc. using Flags property that accepts the values from AnnotationFlags enum.


    Add Annotations

    DsPdf 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:

    1. Create an instance of class corresponding to annotation type you want to add to a page, for example, TextAnnotation class.
    2. Call the Add method to add the annotation on the page.
    Copy Code
    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
    Back to Top

    Get Annotations

    To get the annotations from a page:

    1. Create an instance of the AnnotationCollection class.
    2. Use the AnnotationCollection object to access the annotation by specifying its index.
    Copy Code
    //Get Annotation
    AnnotationCollection acol = doc.Pages[0].Annotations;
    // Display the property values
    Console.WriteLine("Annotation Type: {0}", acol[0].Name);
    Back to Top

    Modify Annotations

    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.

    Copy Code
    //Modify annotation
    textAnnot.Color = Color.BlueViolet;
    textAnnot.Contents = "This is a Text annotation.";
    Back to Top

    Delete Annotations

    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.

    Copy Code
    // Delete all annotations
    // Delete a particular annotation
    Back to Top

    For more information about how to implement annotations using DsPdf, see DsPdf sample browser.