Copy link to clipboard
Copied
Hi,
I hope you could help me too with this. I cant seem to solve why my script wont work. It doesn't leave a color of my choice in the field box. Thank you.
var c = {
'White':['255,255,255'],
'Bright Yellow':['255,210,0'],
'Light Yellow':['255,230,150'],
'Orange':[255,80,30],
'Red':['255,0,0'],
'Green':['0,255,100'],
'Blue':['0,0,255'],
'Dark Blue':['0,15,92'],
'Purple':[120,0,119],
'Dust':['153,26,15'],
'Grey':[200,200,200],
'Black':[0,0,0],
}
var n = new Array('Fill color :');
for (var i in c) n.push(i);
var result = app.popUpMenu(n);
if (result) {
this.fillColor = c[result].toString();
this.border.corner.presence = "hidden";
}
Copy link to clipboard
Copied
Your object c seems to have a wild and wonderful mixture of property types. Arrays containing a single string like "153,26,15". And arrays containing three numbers like 200,200,200. But anyway...
You use
this.fillColor = c[result].toString();
If we assume "result" is the name of a property in c, that might start out as one of your weird and wonderful mixtures (arrays of one string or arrays of three numbers). You then use "toString". So you are setting fillColor to a string.
1. fillColor wants a colour array
2. It isn't an array
3. Even if you passed the array, these are nothing like colour arrays which look more like ["RGB", 1, 0.3, 0.1]. Colour values are not in the range 0 to 255, that's just a strange convention used by some apps. 0.0 to 1.0 is the real colour value.
Copy link to clipboard
Copied
Thank you for your answer. I'm really clueless about this. I just got the code and added more colors. LOL. Maybe that's the reason why a drop down appears but no color is showing when chosen.
I got another, but I just don't like the colors included in this. I need colors orange and light yellow.
But, Thanksssss!
var colors = new Array();
for (var i in color)
colors.push(i); // get a list of colors
while (colors[0] != 'transparent')
colors.shift(); // bump the non-colors
colors.unshift('Choose a Color:'); // label
var choice = app.popUpMenu(colors); // show menu
if (choice != null) // did user select something?
this.getField('swatch').fillColor = eval('color.' + choice);
Copy link to clipboard
Copied
If you want to use more colours you need to use a colour array. Are you trying to do this without detailed study of the Acrobat JavaScript Reference? Programming by copy and paste just won't fly.
Copy link to clipboard
Copied
Yeah, I guess. I'm just doing a pdf file for school purposes. I'm not under this field. Really troubled.
Copy link to clipboard
Copied
Let's take a step back. What are you trying to achieve, exactly?
Copy link to clipboard
Copied
Hi try67,
I'm trying to create a drop down menu of colors: (Red, Blue, Yellow, Light Yellow, Orange, White, Green, Black, Gray, Blue and Purple.) in Adobe Acrobat. I want the people who will answer my survey be able to input their desired colored per text field. But upon searching how, it leads me to javascript. Is there any other way other than that? And thank you so much,
Copy link to clipboard
Copied
So you want them to be able to specify the fill color for each field? Should it only be from a pre-defined list, or should they be able to enter any color they'd like?
Copy link to clipboard
Copied
I want them to be able to choose from a pre-defined list of colors.
(For example, if they typed: "Headache" on the text field, a drop down menu of color choices will appear. Then they will choose what color would theat text field's background to be.)
Copy link to clipboard
Copied
Here's one way of doing it:
var aParams = [
{cName: "White", cReturn: color.white.toSource()},
{cName: "Black", cReturn: color.black.toSource()},
{cName: "Red", cReturn: color.red.toSource()},
{cName: "Orange", cReturn: ["RGB", 255/255,80/255,30/255].toSource()},
];
var cChoice = app.popUpMenuEx.apply( app, aParams );
if ( cChoice != null ) this.getField("Text1").fillColor = eval(cChoice);
Copy link to clipboard
Copied
Thanks so much!
Copy link to clipboard
Copied
The Acrobat JavaScript Color Array documentation. Note the numeric values in the array range from 0 to 1 so you will need to convert the 0-255 scale to a 0-1 scale.
Copy link to clipboard
Copied
Example for color blue:
["RGB", 0, 0, 1]
Copy link to clipboard
Copied
Thanks ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more