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

PDF Color List Drop Down Javascript

Community Beginner ,
Jun 23, 2018 Jun 23, 2018

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";
}

TOPICS
PDF forms
3.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
LEGEND ,
Jun 23, 2018 Jun 23, 2018

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.

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 Beginner ,
Jun 23, 2018 Jun 23, 2018

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);

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
LEGEND ,
Jun 23, 2018 Jun 23, 2018

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.

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 Beginner ,
Jun 23, 2018 Jun 23, 2018

Yeah, I guess. I'm just doing a pdf file for school purposes. I'm not under this field. Really troubled.

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 ,
Jun 23, 2018 Jun 23, 2018

Let's take a step back. What are you trying to achieve, exactly?

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 Beginner ,
Jun 23, 2018 Jun 23, 2018

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,

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 ,
Jun 23, 2018 Jun 23, 2018

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?

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 Beginner ,
Jun 23, 2018 Jun 23, 2018

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

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 ,
Jun 23, 2018 Jun 23, 2018

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);

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 Beginner ,
Jun 24, 2018 Jun 24, 2018
LATEST

Thanks so much!

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
LEGEND ,
Jun 23, 2018 Jun 23, 2018

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.

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 ,
Jun 23, 2018 Jun 23, 2018

Example for color blue:

["RGB", 0, 0, 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 Beginner ,
Jun 23, 2018 Jun 23, 2018

Thanks

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