We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set annotation properties before annotation is added


We are currently exploring the PDF Viewer functionality and to figure out if we can use it inside our projects.
One thing we would like to do is set additional options to the annotation when it is added, for instance by adding a subject or modifying the color.

Right now we are using the AnnotationAdded event but when we try to update the properties of the annotation that is added it doesn't show in the viewer.

Is there a way were we can set the annotation properties before they are processed in the viewer so they are returned correctly?

Some sample code:

<SfPdfViewerServer DocumentPath="@DocumentPath" Height="800px" Width="1060px" >

    <PdfViewerEvents AnnotationAdded="annotationAdd">




    private string DocumentPath { get; set; } = "wwwroot/files/test_03.pdf";

    public void annotationAdd(AnnotationAddEventArgs args)


        // Update the subject of the annotation

        args.AnnotationProperties.Subject = "test subject";

        // Update the color of the annotation

        args.AnnotationProperties.Color = "#7DF066";




3 Replies 1 reply marked as answer

VV Visvesvar Venkatesan Syncfusion Team December 22, 2022 04:12 PM UTC

The annotation add event property is to get the annotation data while adding annotation, we cannot add color in that event.

We can add color using the below code snippet.

Code Snippet

public static PdfViewerAnnotationSelectorSettings selectorSettings = new PdfViewerAnnotationSelectorSettings { ResizerSize = 20, ResizerFillColor = "Yellow"};

    public PdfViewerRectangleSettings rectangleSettings = new PdfViewerRectangleSettings


        AnnotationSelectorSettings = selectorSettings,

          FillColor = "green"


    public static PdfViewerStampSettings stampSettings = new PdfViewerStampSettings


            AnnotationSelectorSettings = selectorSettings,

            FillColor = "green"


    public static PdfViewerFreeTextSettings freeTextSettings = new PdfViewerFreeTextSettings


        AnnotationSelectorSettings = selectorSettings,

        FillColor = "blue"


Kindly find the sample - https://www.syncfusion.com/downloads/support/directtrac/general/ze/SERVER_Sample-2075840481-445627764.zip

Kindly let us know if you have any concerns.

EV Enrico van de Laar replied to Visvesvar Venkatesan December 23, 2022 08:02 AM UTC

Thanks for response!
I think I did not explain the situation correctly.

What we would like to achieve is the following process:

  1. A user selects a word/sentence, right-clicks and selects the "Highlight" option
  2. We show a control outside of the PDF Viewer that allows the user to classify the selected word/sentence
    For instance, they can select a classification of "sensitive" or "hidden".
  3. Based on the selected classification we want to modify the color of the highlighted text.
    For instance, when "sensitive" is selected we want the color to be red, "hidden" gray, etc.
In short we are looking to programmatically set the highlight color based on a user interaction outside of the PDF Viewer. Does this provide more information on what we are trying to achieve?

VV Visvesvar Venkatesan Syncfusion Team December 27, 2022 12:23 PM UTC

Sorry, we don’t have support for your requirement “Text highlight settings must be applied programmatically”, we have logged feature feedback and it will be available in any of our upcoming volume releases next year.

Kindly find the feedback below to track the status of the feature.

Feature - Text highlight settings must be applied programmatically | Feature Feedback

Marked as answer
Live Chat Icon For mobile
Up arrow icon