I have a highlight annotation which is in green color. On particular action performed on that annotation I want to change the color to amber
Please describe your issue and provide steps to reproduce it:
Hello,
I want to know how to change the color of a highlight annotation through code.
Example:
I have a highlight annotation in my pdf which is in red color.
I have added new action button in annotation popup on click of that button I need to change the annotation color from red to green how to do that.
From Core.annotationManager.getSelectedAnnotations();
I am getting the annotation but how to change the color of it not sure can you please help ?
Hello, I’m AiRon, an automated tech support bot While you wait for one of our customer support representatives, I can help you with your question.
To change the color of a highlight annotation in WebViewer, you can use the setStyles API to modify the annotation’s properties. Once you have the annotation object, you can update its StrokeColor or FillColor to change its appearance.
Some things you can try:
Retrieve the annotation object using Core.annotationManager.getSelectedAnnotations().
Check if the annotation is of type HighlightAnnotation.
Use the setStyles function to change the StrokeColor or FillColor to the desired color (e.g., amber).
Update the annotation on the page using Core.annotationManager.redrawAnnotation.
To change the color of a highlight annotation on select, you could do something like this:
const { annotationManager, documentViewer, Tools, Annotations, } = instance.Core
document.getElementById('sample-button').addEventListener('click', async e => {
// assuming only one annotation is selected
const selectedAnnotation = annotationManager.getSelectedAnnotations()[0]
if (selectedAnnotation instanceof Annotations.TextHighlightAnnotation) {
selectedAnnotation.StrokeColor = new Annotations.Color(0, 128, 0); // Green
selectedAnnotation.FillColor = new Annotations.Color(0, 0, 255); // Optional: fill color blue
annotationManager.redrawAnnotation(selectedAnnotation)
}
})