• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to change button caption color in pdf by javascript

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

1.3K

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
community guidelines
Community Expert ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

What is the value of variable "bn" ?

Votes

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
community guidelines
Explorer ,
Dec 13, 2019 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.

Votes

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
community guidelines
Community Expert ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Dec 13, 2019 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.

Votes

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
community guidelines
Community Expert ,
Dec 13, 2019 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)?

Votes

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
community guidelines
Community Expert ,
Dec 13, 2019 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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Explorer ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines