How can I programmatically create a specific color (such as blue, green) rectangle annotation using javascript?

I have on java script function to create a rectangle annotation in Pdf Viewer using 

 pdfViewer.annotation.setAnnotationMode('Rectangle');

This will allow user to create a red rectangle annotation. 


However, I have a new requirement from user to create a new button which do exactly the same as previous button but change the color of annotation to other color like green, blue, etc. Manually change color from the UI is not accepted in this case. 


What I can think of is let the created annotation to be red. and after then modify those annotations color using API. Is this also possible? 


Any suggestion would be really appreciate.


Best Regards,

AT.


1 Reply

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team August 3, 2022 03:55 PM UTC

Hi Asana,


Yes, we can able to change the rectangle annotation color programmatically. We have shared the sample for this.


Sample -  https://stackblitz.com/edit/qgf55a?file=index.html,index.js,package.json


Steps to change the rectangle annotation color programmatically :


  • Run the sample .
  • Click the button "Change Color(Blue)". And then click the Add Rectangle annotation button, Now add the rectangle annotation, it appears in blue color.
  • Click the button "Change Color(Green)". And then click the Add Rectangle annotation button, Now add the rectangle annotation, it appears in green color.



Regards,

CCM Karthik


Loader.
Up arrow icon