How to Use Custom RGB Colors in Acrobat JavaScript
Question details
The user needs to apply custom RGB colors using Acrobat JavaScript, which requires a normalized value format.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing or editing JavaScript in a PDF document to set custom text or element colors.
- Observed behavior
- Acrobat JavaScript requires normalized color component values ranging from 0.0 to 1.0 instead of the standard 0-255 RGB scale.
Ensure you have the exact standard RGB values (0-255) for the custom color you want to use before writing your Acrobat JavaScript code.
Convert Standard RGB to Normalized Values
Divide each standard RGB component by 255 to get the normalized values required by Acrobat JavaScript.
Acrobat JavaScript uses a color array format where each color channel (Red, Green, Blue) is represented by a decimal value between 0.0 and 1.0. To use standard RGB colors, a simple mathematical conversion is required.
Determine the Red, Green, and Blue values of your desired color on the 0-255 scale (for example, R: 0, G: 112, B: 192).
Divide each individual RGB value by 255 using a calculator or script. For example, 0 / 255 = 0, 112 / 255 = 0.4392, and 192 / 255 = 0.7529.
Construct the color array in your Acrobat JavaScript code using the 'RGB' color space identifier followed by the normalized values. For example: ["RGB", 0, 0.4392, 0.7529].
Assign this formatted array to the relevant property in your script, such as setting the text color using event.target.textColor = ["RGB", 0, 0.4392, 0.7529];

Change Text and Element Colors Directly in WPS PDF
Instead of writing complex JavaScript to change colors, you can use WPS Office's built-in PDF editor to visually select and apply custom RGB colors to your text and shapes in seconds.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document.
- 2. Enter Edit Mode: Click on the 'Edit' tab at the top toolbar and select 'Edit Text' or 'Edit Object'.
- 3. Select Text and Change Color: Highlight the text, click the font color icon in the floating menu, and click 'More Colors' to input your standard 0-255 RGB values.
- 4. Save your document: Once the custom color is applied visually, click the 'Save' icon to preserve your changes.

Frequently Asked Questions
Why does Acrobat JavaScript use a 0.0 to 1.0 scale for RGB?
Acrobat uses normalized color values to maintain consistency across different color spaces (like CMYK, RGB, and Grayscale) within its JavaScript API, representing percentages of color intensity rather than absolute 8-bit integer values.
How do I define a CMYK color in Acrobat JavaScript?
Similar to RGB, CMYK colors use a normalized 0.0 to 1.0 scale. You define it using the 'CMYK' identifier followed by four decimal values representing Cyan, Magenta, Yellow, and Key (Black). For example: ["CMYK", 1, 0.5, 0, 0].
Can I use hexadecimal color codes (like #FF0000) in Acrobat JavaScript?
Acrobat JavaScript does not natively accept hex color codes. You must first convert the hex code to standard RGB (0-255), and then divide those values by 255 to get the normalized array format required by Acrobat.
What are the predefined colors in Acrobat JavaScript?
Acrobat JavaScript includes several predefined color arrays for convenience, such as color.black, color.white, color.red, color.green, and color.blue, which can be used directly without array formatting.




