How to change button caption color in pdf by javascript

Community Beginner ,
Dec 13, 2019

Copy link to clipboard

Copied

Hi There,

I want to toggle the button color of a pdf form along the with the caption/label color of each button. For this, I have written this code:

 

for(i=1;i<bn+1;i++){
var b = "btn"+i;
var f = this.getField(b);
if (color.equal(f.fillColor, color.white)){
f.textColor = color.white;
f.fillColor = color.red;
}else{
if(bn==1){
f.fillColor = color.white;
f.textColor = color.black;
}else{
f.textColor = color.black;
}
}

 

Everything is working well except for the color of the Caption/Label. It is black in default and remains black even the fill color is changing. How to change the Caption/Label color to white too?

TOPICS
Acrobat SDK and JavaScript

Views

250

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

How to change button caption color in pdf by javascript

Community Beginner ,
Dec 13, 2019

Copy link to clipboard

Copied

Hi There,

I want to toggle the button color of a pdf form along the with the caption/label color of each button. For this, I have written this code:

 

for(i=1;i<bn+1;i++){
var b = "btn"+i;
var f = this.getField(b);
if (color.equal(f.fillColor, color.white)){
f.textColor = color.white;
f.fillColor = color.red;
}else{
if(bn==1){
f.fillColor = color.white;
f.textColor = color.black;
}else{
f.textColor = color.black;
}
}

 

Everything is working well except for the color of the Caption/Label. It is black in default and remains black even the fill color is changing. How to change the Caption/Label color to white too?

TOPICS
Acrobat SDK and JavaScript

Views

251

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
Dec 13, 2019 0
Adobe Community Professional ,
Dec 13, 2019

Copy link to clipboard

Copied

What is the value of variable "bn" ?

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...
Dec 13, 2019 0
Community Beginner ,
Dec 13, 2019

Copy link to clipboard

Copied

It is the current button number. Let's say I have five buttons which names are btn1, btn2, btn3, btn4 & btn5 respectively.

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...
Dec 13, 2019 0
Adobe Community Professional ,
Dec 13, 2019

Copy link to clipboard

Copied

Where does you set or change the variable "bn" ?

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...
Dec 13, 2019 0
Community Beginner ,
Dec 13, 2019

Copy link to clipboard

Copied

Actually this function will be put on Document Label (let's say function name is bcolor(bn) and in every button, an action will be set. As for example in btn3, the javascript action will be:

 

bcolor(3)

 

where 3 is the current button number and 5 is the highest button number.

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...
Dec 13, 2019 0
Adobe Community Professional ,
Dec 13, 2019

Copy link to clipboard

Copied

For this sample the fill color will be changed from white to red.

 

What happens when you use bcolor(1)?

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...
Dec 13, 2019 0
Adobe Community Professional ,
Dec 13, 2019

Copy link to clipboard

Copied

So you are saying that when the fill color is changing to red, that the text color does not change to black?

You're code looks correct and "textColor" is the right property.  I would suggest putting "console.println()" statements into the code so you can see which code blocks are being run with which button numbers. 

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...
Dec 13, 2019 0
Community Beginner ,
Dec 13, 2019

Copy link to clipboard

Copied

No, I want when the fill color will be red, at that time text color will be white so that text can be seen clearly.

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...
Dec 13, 2019 0