Search code examples
javascriptacrobat

Select a Textbox using the Subject


I am wanting to be able to select a Acrobat Text Box or Polygon using the Subject as the selector.

Eg.

I have a Shape with a subject of "Test.Shape.01" I want to select that shape as a variable then change the fill and border colours.

How would I go about achieving this?


Solution

  • This should do the trick...

    this.syncAnnotScan();
    var annots = this.getAnnots();
    for (var i = 0; i < annots.length; i++) {
        if (annots[i].subject == "Test.Shape.01") {
            annots[i].fillColor = color.red; // for example
            annots[i].strokeColor = color.red;
            break; // if you know there is only one. Remove if there might be more than one.
        }
    }
    

    The first line will force Acrobat to rescan the document for any annotations that may have been added since the last time it scanned. Then you simply loop through all of the annotations looking for the ones with the subject you need and them modify their properties. You can see a list of named colors here... https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fcolor_properties.htm

    If you're unsure about where to add this script, tell me more about exactly what you are trying to achieve.