Skip to main content
amandad98552352
Participant
October 6, 2017
質問

Change color to hex values in javascript

  • October 6, 2017
  • 返信数 2.
  • 2596 ビュー

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

このトピックへの返信は締め切られました。

返信数 2

JR Boulay
Community Expert
Community Expert
October 6, 2017

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]

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
October 6, 2017

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]