Reputation: 17
I need to create several buttons in a PDF which when pressed will change the color of the Ink/Pencil tool in Acrobat. I am not proficient in JavaScript and have been struggling to find adequate documentation for what I am trying to accomplish.
I have found a way to do the reverse, I can make an annotation and have the button change the color of the Ink after it has been drawn. This satisfies my needs but I have not figured out how to only edit the LAST modified/created annotation. So far I have the following:
var buttonColor = this.getField("button").strokeColor;
this.syncAnnotScan();
var annots = this.getAnnots()
nSortBy: ANSB_ModDate
bReverse: true;
for (var i = 0; i < annots.length; i++) {
if (annots[i].type == "Ink") {
annots[i].strokeColor = buttonColor;
}
}
This results in the button changing ALL Ink annotations; I am just not sure how to tell the script to only edit the LAST created/modified annotation (if possible), everything else is working as needed.
Upvotes: 0
Views: 317
Reputation: 4907
You don't need to sort the annots to get to the last one created, it's always the last item in the array. You don't need to pass any parameters to getAnnots().
var buttonColor = this.getField("button").strokeColor;
this.syncAnnotScan();
var annots = this.getAnnots();
if (annots[annots.length-1].type == "Ink") {
annots[annots.length-1].strokeColor = buttonColor;
}
You can see a PDF with this working at the URL below. https://files.acrobat.com/a/preview/69dd17f9-66f5-496b-a2d1-bfaab21ccdec
Upvotes: 1