Change fill color with Javascript

Community Beginner ,
Nov 26, 2019

Copy link to clipboard

Copied

Hi.

I have pdf files with lots of markups (rectangles, ovals) and would like to use Javascript to automatically change their fill color to none and line thickness to 2 pt. Can someone help me out with the code?

Thanks!

TOPICS
Acrobat SDK and JavaScript, Comment review and collaborate PDF, How to

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Change fill color with Javascript

Community Beginner ,
Nov 26, 2019

Copy link to clipboard

Copied

Hi.

I have pdf files with lots of markups (rectangles, ovals) and would like to use Javascript to automatically change their fill color to none and line thickness to 2 pt. Can someone help me out with the code?

Thanks!

TOPICS
Acrobat SDK and JavaScript, Comment review and collaborate PDF, How to

Views

71

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 26, 2019 0
Community Beginner ,
Nov 26, 2019

Copy link to clipboard

Copied

OK, here's what I got so far:

 

this.syncAnnotScan();
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++)
if (annots[i].type == "Circle" || "Square") annots[i].width = 2, annots[i].fillColor = color.transparent;

 

Now there is just one issue with this script, it also somehow applies the properties to polygon objects. When I run the script individually for circle and square, it works fine. When both are listed as above, the polygon gets changed, too. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 26, 2019 0
Community Beginner ,
Nov 26, 2019

Copy link to clipboard

Copied

OK, small syntax error. Here's the working script:

 

this.syncAnnotScan();
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++)
if (annots[i].type == "Circle" || annots[i].type == "Square") annots[i].width = 2, annots[i].fillColor = color.transparent;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 26, 2019 0
Adobe Community Professional ,
Nov 26, 2019

Copy link to clipboard

Copied

You are very close. 

 

this.syncAnnotScan();
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++)
{
     if (annots[i].type == "Circle" || annots[i].type == "Square")
     {
            annots[i].width = 2;
            annots[i].fillColor = ["T"];
      }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 26, 2019 0