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

How to change button caption color in pdf by javascript

Explorer ,
Dec 13, 2019 Dec 13, 2019

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
1.7K
Translate
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

What is the value of variable "bn" ?

Translate
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

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

Translate
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

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

Translate
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

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.

Translate
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

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

 

What happens when you use bcolor(1)?

Translate
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

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

Translate
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
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.

Translate
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