Skip to main content
amandad98552352
Participant
Oct 6, 2017 3:17 PM UTC
Question

Change color to hex values in javascript

Hi there,

I am using this script within my custom keystroke script:

// Custom Keystroke script for dropdown

(function () {

    if (!event.willCommit) {

        exp_val = event.changeEx;

        // Get a reference to the text field

        var f = getField("DD39");

        // Set the stroke color of the text field based on the dropdown selection

        switch (exp_val) {

        case "0" :

            f.fillColor = color.green;

            break;

        case "1" :

            f.fillColor = color.blue;

            break;

        case "2" :

            f.fillColor = color.yellow;

            break;

        case "3" :

            f.fillColor = color.red;

            break;

        default :

            f.fillColor = color.white;

            break;

        }

    }

})();

However I would really like to use custom color values, rather than the defaults. What is the syntax? I've tried a few things but nothing works.

Thanks

Amanda

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

JR Boulay
Community Expert
Community Expert
Oct 6, 2017 4:27 PM UTC

Converting colors to 0-1 is easy for CMYK but not for RGB.

You can use the real RGB values instead : ["RGB", 128/255, 167/255, 99/255]

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
Oct 6, 2017 3:30 PM UTC

You should read up about the color object in the Acrobat JS Reference, but basically it's an array with the color space followed by the values, represented by a number from 0 to 1.

For example:

["RGB", 0, 1, 1]

or

["CMYK", 0.14, 0.23, 0, 1]

Translate