How to Apply Different Text Colors to Variables in a PDF Form
Question details
The user needs to format a specific text variable, inserted via a dropdown script, with a different text color than the surrounding text in a PDF form field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Using a dropdown validation script to dynamically insert mixed-color text (static text plus a colored description variable) into a single form field.
- Observed behavior
- Standard form fields only support plain text, which strictly applies a single uniform color to all contents, preventing specific variables from having a unique color.
Ensure you have access to the PDF form's JavaScript editor and verify that the target text field allows rich text formatting to process dynamic color styling.
Enable Rich Text Formatting and Use JavaScript Span Objects
Convert the target field to support rich text and use an array of Span objects in JavaScript to assign unique colors to specific text segments.
Standard PDF form fields use plain text, which enforces a single style and color across the entire field. To colorize only a specific variable inserted by a dropdown script, you must utilize the field's rich text capabilities combined with JavaScript.
By building an array of Span objects in your script, you can define specific formatting properties (like color) for individual chunks of text, and then push that formatting to the field.
Open your PDF form in Adobe Acrobat and enter the 'Prepare Form' mode to access field properties.
Right-click the target output text field, select 'Properties', navigate to the 'Options' tab, and check the box for 'Allow Rich Text Formatting'.
In your dropdown validation script, build an array of Span objects. Assign your desired color (e.g., color.red) to the specific span object that contains the inserted description variable, while keeping the default color for the surrounding text spans.
Instead of setting the field's standard `value` property, assign your constructed Span array to the target field's `richValue` property to apply the mixed-color formatting.
Edit PDF Forms and Text Colors Easily with WPS Office
WPS Office provides a comprehensive PDF editing suite that allows you to effortlessly manage PDF forms, edit text layouts, and apply rich formatting without complex scripting.
- 1. Open the PDF document: Launch WPS Office and open your target PDF file containing the forms or text you wish to edit.
- 2. Access the edit tools: Navigate to the 'Edit' tab on the top ribbon and select 'Edit Text' to enable direct modifications to static text and form layouts.
- 3. Adjust text colors: Highlight the specific text or form area you want to change, and use the floating properties panel to select a new text color.
- 4. Save your changes: Once the formatting is applied, click the 'Save' icon to preserve the new text styling in your standard PDF file.

Frequently Asked Questions
Why does my PDF text field apply one color to all words?
By default, PDF text fields are set to plain text format. This strictly enforces a single style, font, and color across the entire field. To apply different styles to individual words or variables, you must enable 'Allow Rich Text Formatting' in the field's options.
Can I manually change text colors in a PDF form without using JavaScript?
Yes. If the form field has rich text formatting enabled, users filling out the form can manually select text within the field and change its color using the text properties toolbar (often accessed via Ctrl+E). However, automating this process upon selection still requires JavaScript.
What is a Span object in PDF JavaScript?
A Span object is a JavaScript element used in rich text formatting within PDFs. It represents a continuous segment of text that shares the same formatting properties, such as font style, weight, size, and text color.




