PDF Editing Issues

How to Change the Color of a PDF Form Figure Using a Button

Tauseeq MagsiTauseeq Magsi Nov 5, 2026 868 views

Question details

The user wants to configure an interactive button within a PDF form to dynamically change the color of a specific figure or object upon clicking.

How to Change the Color of a PDF Form Figure Using a Button
Product
PDF Form
Device & OS
not provided
Scenario
Creating dynamic and interactive PDF forms where clicking a button triggers a visual change, such as a color shift, in another document element.
Observed behavior
The correct method depends heavily on the specific object type being targeted (form field, annotation, or static drawn shape), which determines the required property settings or JavaScript.
Before you start

Identify exactly what type of figure you are trying to change. Standard drawn shapes are static, so you will need to replace the figure with an interactive form field or button to manipulate its color via actions.

Solution 1Recommended

Use JavaScript to Change a Form Field Color via Button

The most reliable way to change an object's color dynamically in a PDF is by treating the target figure as a read-only form field and applying a JavaScript mouse-up action to the control button.

Interactive PDFs rely on form fields to execute visual changes. By setting up your target figure as a button or text field with no text, you can use built-in PDF JavaScript to manipulate its fill or stroke color.

1
Create the target figure as a field

Insert a new Button or Text Field into your PDF to act as the visual figure you want to color. Right-click it, select 'Properties', and name it exactly 'TargetFigure'. Set its read-only status so users cannot type in it.

2
Create the control button

Insert another Button form field into your document. This will serve as the interactive trigger the user clicks to change the color.

3
Access button actions

Right-click your newly created control button, select 'Properties', and navigate to the 'Actions' tab.

4
Configure the JavaScript action

Under 'Select Trigger', choose 'Mouse Up'. Under 'Select Action', select 'Run a JavaScript', then click the 'Add' button to open the script editor.

5
Input the color code

Enter the script `this.getField('TargetFigure').fillColor = color.red;` and click 'OK' to save. You can replace 'color.red' with 'color.blue', 'color.green', or 'color.transparent' as needed.

Use JavaScript to Change a Form Field Color via Button
Object Types Matter: If your original figure is an annotation or a drawn object rather than a form field, standard PDF JavaScript might not interact with it directly. Replacing it with a form field is highly recommended for cross-compatibility.
Advanced PDF Form Editing

Create and Edit Interactive PDF Forms with WPS PDF

WPS Office provides robust PDF form editing tools, allowing you to seamlessly insert interactive buttons, configure field properties, and manage advanced form actions without relying on complex external software.

  1. 1. Open your PDF Form: Launch WPS Office and open your PDF document utilizing the built-in WPS PDF editor.
  2. 2. Access the Form tab: Navigate to the 'Form' tab on the top ribbon to access the suite of interactive form elements.
  3. 3. Insert and configure buttons: Click 'Push Button' or 'Text Field' to add elements, then double-click the placed element to configure its appearance, names, and custom actions.
Easily insert text fields, checkboxes, and interactive buttons into your documents.Configure form properties and button trigger actions directly from a user-friendly interface.Fully compatible with standard PDF form functionalities and Adobe Acrobat formats.
microsoft office alternative - wps office

Frequently Asked Questions

Can I change the color of a standard drawn shape (like a rectangle) using a PDF button?

Standard PDF drawn shapes are usually static graphical elements and cannot be altered dynamically with a button click. It is highly recommended to replace the static shape with a read-only button field or text box, which can then be targeted by JavaScript.

What JavaScript color formats are supported in PDF forms?

PDF JavaScript supports predefined color arrays (e.g., color.red, color.blue, color.black, color.transparent) as well as specific RGB and CMYK array configurations, such as ['RGB', 1, 0, 0] for pure red.

Why isn't my PDF button changing the color after I added the script?

Ensure that the name of the target field inside your JavaScript script exactly matches the actual field name under the PDF properties. PDF JavaScript is case-sensitive. Additionally, check that your current PDF viewer supports and has enabled JavaScript execution.