PDF Editing Issues

Add Conditional Colors and Risk Labels to a PDF Form

Camila MilosovichCamila Milosovich Oct 28, 2026 869 views

Question details

The user wants a score field in a PDF form to dynamically display a specific risk label and change its background color based on a calculated score range.

How to Add Conditional Colors and Risk Labels to a PDF Form
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF risk calculator that multiplies likelihood and impact values, and visually updates the result field based on defined risk thresholds.
Observed behavior
The goal state is for the result field to show labels like Very Low, Low, Moderate, or High with corresponding fill colors, and to remain transparent when input values are zero or empty.
Before you start

Ensure you are using a PDF editor that supports advanced form editing and JavaScript execution, such as Adobe Acrobat Pro, as conditional formatting in PDFs relies on scripting.

Solution 1Recommended

Use a Custom JavaScript Calculation Script

Apply a custom JavaScript calculation to the result field to multiply the inputs, determine the correct text label, and apply the corresponding background color.

PDF forms support custom JavaScript to calculate values and dynamically change field properties. You can write a script that reads the input fields, computes the final score, and updates both the text value and background color of the target field depending on the result.

1
Open Form Preparation Mode

Open your PDF document in your advanced form editor and select the 'Prepare Form' tool to make the fields editable.

2
Access Field Properties

Right-click the result or score text field where you want the label and color to appear, and select 'Properties' from the context menu.

3
Add a Custom Calculation

Navigate to the 'Calculate' tab in the Properties dialog. Select the 'Custom calculation script' radio button, then click the 'Edit' button.

4
Enter the JavaScript Code

Write a script that retrieves the values of your input fields, multiplies them, and uses an if/else structure to set `event.value` (the text label) and `event.target.fillColor` (an array like `["RGB", 1, 0, 0]`) based on the score. Add a condition checking if inputs are zero or empty to set `event.target.fillColor = color.transparent;`.

5
Save and Test

Click 'OK' to save the script, close the properties window, and test your form by entering different values to see if the colors and labels update correctly.

Use a Custom JavaScript Calculation Script
Scripting Syntax: Ensure that the field names referenced in your JavaScript exactly match the actual names of the fields in your PDF form. JavaScript is case-sensitive.
Edit PDF Forms with WPS Office

Create and Fill Interactive PDF Forms with WPS Office

WPS Office provides comprehensive PDF editing tools, allowing you to create interactive forms, add text fields, insert dropdown menus, and fill out complex PDF documents seamlessly.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access various form controls like Text Fields, Check Boxes, and Combo Boxes.
  3. 3. Edit Form Properties: Double-click any inserted form field to modify its properties, appearance, and specific options.
  4. 4. Save and Export: Once your form is completely set up, save your document to ensure all interactive elements are preserved.
Easily create and edit interactive PDF forms with specialized form toolsHigh compatibility with standard PDF format featuresAdd text boxes, checkboxes, and dropdowns without hassleLightweight application with a user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Can I change a PDF field's color without using JavaScript?

Basic PDF form editors typically do not support conditional formatting natively without scripting. You will need to use a custom JavaScript calculation to change a field's color dynamically based on its calculated value.

Why isn't my PDF custom calculation script working?

Common reasons include JavaScript syntax errors, mismatched field names (which are strictly case-sensitive), or security settings in your PDF viewer that block JavaScript execution. Double-check your script in the editor's JavaScript console.

How do I make the field transparent if there is no input?

In your custom calculation script, include an 'if' statement checking if the input fields are empty or evaluate to zero. If true, set `event.target.fillColor = color.transparent;` and `event.value = "";` to clear the field.