Search code examples
javascriptannotationsacrobat

Changing Annotation Fill based on current fill colour


I am trying to change the fill and stroke colour of an annotation based on the current fill or stroke colour.

Eg the current RGB of the Annotations fill is:

["RGB", 170/255, 110/255, 40/255]

I need to change all annotations with this fill too:

["RGB", 255/255, 250/255, 180/255]

I have the following but am making no headway.

    this.syncAnnotScan();
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++) {
    if (annots[i].fillColor == ["RGB", 170/255, 110/255, 40/255]) { // What is the colour we are searching for?
        annots[i].fillColor = ["RGB", 255/255, 250/255, 180/255]; // Fill Colour Change
        annots[i].strokeColor = ["RGB", 255/255, 250/255, 180/255]; // Stroke Colour Change 
    }
}

Any help on this would be much appreciated.


Solution

  • You need to do a color.equal(), as per documentation states: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf on page 430

    this.syncAnnotScan();
    var annots = this.getAnnots();
    var annotsLength = annots.length;
    var colourTarget = ["RGB", 0.9019622802734375, 0.0980377197265625, 0.2941131591796875];
    var colourChangeTarget = ["RGB", 255/255, 250/255, 180/255];
    
    for (var i = 0; i < annotsLength; i++)
    {
        if(color.equal(annots[i].fillColor, colourTarget))
        {
            annots[i].fillColor = colourChangeTarget;
            annots[i].strokeColor = colourChangeTarget;
        }
    }