These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Colors and samples

Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Answered

What I need to do :
· Users need to import XML datas in a form listing some colors.
· (The list of color is never the same)
· Next to the color, we need a sample of the color.
 
The problem :
· No worries to import the names of the colors
· But HOW CAN I GET THE COLOR SAMPLE?
 
Possible solutions :
· Is it possible to set the color of a box by importing an Hexadecimal color code for instance? (i.e. Background color...)
· Or by importing an image ?
· Or anything....
 
Please, help me. I've been working on this problem for weeks and except driving me crazy I have no results !
I hope my explanations are clear enough.

n/a
My Product Information:
Acrobat Pro 9.4, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
Fields colors can be specified using RGB or CMYK values. So you could populate a field with those values and use JavaScript to set the background color of the field, or a different field, to the specified color. The details depend on how you choose to pass the data.
Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Great!
Thank you very much for this quick answer George.
I have no idea how to write a JavaScript yet, but it's giving me hope !

I was thinking of importing the color name in a field using XML then importing the color "code" in the sample color field to use this data to change the color using a script.
Just like you said.... If I understood correctly!

So, now, I just need to find information on how to write this script.
n/a
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
So will you have access to the corresponding RGB or CMYK values? If so, will each component value range from 0-1, or 0-255? If not, you will have to get them. We can help with the specific code if provide a bit more info.
Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Yes, I do have the color values in RGB. Actually that's how they are set and used in other programs too (InDesign and Illustrator).

For instance something like 0,0,0 or 255,255,255 or 212,36,7
n/a
maxwyss
Registered: Jul 25 2006
Posts: 255
If it is RGB, you will at one point have to scale the values, as Acrobat JavaScript's range for a channel is between 0 and 1. In other words, you will have to divide the R, G, B numbers by 255.

No big deal, but something which can cause issues...

HTH.

Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Cool, thanks for the tip. I'm sure that would have cost me my last hair!
n/a
Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Is it too much if I ask you if you know a place full of treasures and JavaScripts like the one I need ? :.)

Yes, I know, Google...
n/a
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Here's a script you can use as the custom Validate script for the field that you will pass the RGB values to. It assumes that the values will be specified in a string like:

"25,123,254"

But don't include the quotes.

When the data is imported and the value of the field is set, the script will be triggered and the background color of the text field will change to the color specified by the RGB values. If the field gets changed to blank, the background color will get set to white.

// Custom Validate script for text field
(function () {

// Get the current field value
var vals = event.value;

// If the field is blank, set the fillColor to white
if (event.value === "") {
event.target.fillColor = color.white;
return;
}

// Create an array containing the individual RGB values
var vals_array = vals.split(",");

// Divide each value by 255
vals_array[0] = vals_array[0] / 255;
vals_array[1] = vals_array[1] / 255;
vals_array[2] = vals_array[2] / 255;

// Create a color array to specify as the fillColor
var c_array = ["RGB", vals_array[0], vals_array[1], vals_array[2]];

// Set this field's fillColor to RGB value specified
event.target.fillColor = c_array;

})();


This could be simplified a bit, but I wanted to make it understandable. There could also be some validation added that checks for a valid color, so post again if you need that or want things to behave differently.

If you want to hide the text so the RGB values don't show, use the following as the text field's custom Format script:

// Custom format script for the text field
event.value = "";
Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
So cool!

That's brilliant! Problem completely solved!

Thank you "so very much"!
And the script is very cleared. I understand everything.
It's exactly what I needed. You made my day!

Thanks again George.

n/a
Benoit Pennecot
Registered: Apr 30 2010
Posts: 7
Hello George,

It's me again !!!! :.D
You saved my life a couple of months ago with this great script.

The good news is that it works perfectly. I'm so glad ! The bad news is that I had to redo all my form in LiveCycle Designer for different reasons. I'm a designer, not a programer.
I understand all the script you wrote above, but I guess some instructions or syntax might be different in LCD.

I literally spent the whole day trying to make it work in LCD playing around with the code, with no success !

I added the script as a 'validate' event.
and if I put something like

if ($.rawValue == "") then
fillColor = "0,255,0";

I get some green. That gives me some hope. But that's as far as I managed to get ! :.(

So I guess the script you proposed above needs a bit of adjustment.

Could I dare asking you to help me on this one ? PLEEEEASE !
n/a
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876