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

Change color to hex values in javascript

New Here ,
Oct 06, 2017 Oct 06, 2017

Copy link to clipboard

Copied

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

TOPICS
PDF forms

Views

2.1K

Translate

Translate

Report

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 ,
Oct 06, 2017 Oct 06, 2017

Copy link to clipboard

Copied

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]

Votes

Translate

Translate

Report

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 ,
Oct 06, 2017 Oct 06, 2017

Copy link to clipboard

Copied

LATEST

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]

Votes

Translate

Translate

Report

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