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

JavaScript - FillColor change menu - does not work

Community Beginner ,
Jan 28, 2020 Jan 28, 2020

Hi everyone,

 

I've tried to find my solution on tons of topics, but it is not solving my problem.

 

I have a JavaScript on Adobe Acrobat to create a drop down menu with colors. Anyone using this PDF should be able to have this menu on each text box to be able to can change the background color individually.

 

The menu shows and you can select an element, but the visual effect does not work. Looks like it can be the "c[result]" code, but I don't know what could replace it.

 

My code is this one:

______

var c = {

    'White':['255,255,255'],

    'Red':['255,0,0'],

    'Green':['0,255,0'],

    'Grey':[170,170,170],

}

var n = new Array('Background color');

for (var i in c) n.push(i);

 

var result = app.popUpMenu(n);

if (result) {

    this.fillColor = c[result].toString();

}

______

 

Pleas help! Thanks

TOPICS
General troubleshooting , How to , PDF forms
1.4K
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 ,
Jan 28, 2020 Jan 28, 2020

Are there any messages in the JavaScript console? Also, try adding an else so if result is unexpected you get an alert.

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 ,
Jan 28, 2020 Jan 28, 2020
Thanks for your reply. I'm really a dummy on this, I found this script and did basic mods to achieve my goal. I don't see any Java console that gives me substitute or suggestions (attached are the windows I see).

Also I could add a an else, but I don't know what line would suits best my interest.

Original script was this original didn't work either):


var c = {

'White (RGB)':['255,255,255'],

'Red (RGB)':['255,0,0'],

'Green (RGB)':['0,255,0'],

'Blue (RGB)':['0,0,255'],

'Dust (RGB)':['153,26,15'],

'Dark blue (RGB)':['0,15,92'],

'Purple (RGB)':[120,0,119],

'Grey (RGB)':[200,200,200],

}



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

}
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 ,
Jan 28, 2020 Jan 28, 2020

Also, what is this color value - ['255,255,255'] - this is an array containing one string element, not at all what a color value needs to be (it is an array of one string and some numbers in the range 0 to 1 - no 255 in it anywhere! See https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/

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 ,
Jan 28, 2020 Jan 28, 2020
255.255.255 are RGB value for white.
 
I'll check the liked you added, maybe a different color language will make this work. I've tried HEX values also based on another forum that had java codes with HEX values (like #FFFFFF = white)
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 ,
Jan 28, 2020 Jan 28, 2020

No, they are not the RGB values for white in Acrobat JavaScript. You can't guess, read the document, which is much more accessible than the JavaScript API in this.

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 ,
Jan 28, 2020 Jan 28, 2020

JavaScript console, Ctrl+J. Virtually impossible to get a program right without it, even for people with decades of experience in writing it...

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 ,
Jan 28, 2020 Jan 28, 2020
Thanks, I'll try.
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 ,
Jan 28, 2020 Jan 28, 2020

Ah, I think I found the code you copied at https://answers.acrobatusers.com/Change-background-color-on-mouse-click-q289742.aspx  Unfortunately, this is JavaScript for LiveCycle Designer, not Acrobat. A nasty trap for the unwary, because it also works with PDF, but the scripting is completely different. You NEED the Acrobat JavaScript Reference. https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf (warning: this is very large, 769 pages to study)

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 ,
Jan 28, 2020 Jan 28, 2020
LATEST

You have a rather simple issue here. The color values specified in your array are not Acrobat JavaScript Colors. All you need to do is change the color values to use the correct specification:

Here's an article on the topic:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/

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