Skip to main content
infomamun
Inspiring
December 13, 2019
Question

How to change button caption color in pdf by javascript

  • December 13, 2019
  • 2 replies
  • 1918 views

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?

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
December 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
infomamun
infomamunAuthor
Inspiring
December 13, 2019

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.

Bernd Alheit
Community Expert
Community Expert
December 13, 2019

What is the value of variable "bn" ?

infomamun
infomamunAuthor
Inspiring
December 13, 2019

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

Bernd Alheit
Community Expert
Community Expert
December 13, 2019

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