How to Make Part of a Calculated PDF Field Bold with JavaScript
Question details
The user wants to format a specific portion of a calculated text field in a PDF form to be bold using JavaScript, rather than applying bold text to the entire field.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form where a calculated field outputs a dynamic string, and specific words within that string need emphasis.
- Observed behavior
- Standard value assignments apply one uniform text style to the entire field, preventing mixed formatting like bold and regular text in the same output.
Ensure you are using a professional PDF editor that supports JavaScript form calculations and has options to enable Rich Text Formatting for form fields.
Use Rich Text Formatting and the event.richValue Property
Enable Rich Text Formatting on the text field and use the event.richValue array in JavaScript to apply distinct font weights to different text segments.
To format only a portion of a text field in a PDF form, you cannot use the standard event.value property because it only supports plain text. Instead, you must pass an array of rich text objects to the event.richValue property. Each object in the array represents a segment of text and can contain its own styling properties, such as font weight for bolding.
Open your PDF form in editing mode. Right-click the target calculated text field, select 'Properties', and navigate to the 'Options' tab. Check the box labeled 'Allow Rich Text Formatting'.
Switch to the 'Calculate' tab within the same Properties window. Select 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.
Instead of using event.value, assign an array to event.richValue. For example: if (selection == "Package C") { event.richValue = [{text: "Package C includes", fontWeight: 800}, {text: ": X, Y, and Z"}]; }
Click 'OK' to save the script, close the properties window, and test your form. The text defined with fontWeight 800 will now appear bold, while the rest remains normal.

Easily Edit and Manage Interactive PDF Forms with WPS Office
WPS Office provides a robust suite of PDF tools, allowing you to create, edit, and manage interactive PDF forms with ease while ensuring compatibility with standard PDF formats.
- 1. Download WPS Office: Download and install WPS Office Free on your computer or mobile device.
- 2. Open Your PDF Document: Launch the WPS PDF tool and open the interactive PDF form you wish to edit.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access various form controls and editing options.
- 4. Customize and Save: Adjust your text fields, configure calculation properties, and save your fully customized PDF form.

Frequently Asked Questions
Why is my JavaScript calculation ignoring the bold formatting?
If your script is running but the text isn't bold, it is highly likely that 'Allow Rich Text Formatting' is not checked in the text field's properties. Without this setting enabled, the PDF viewer will ignore the rich text array and treat the output as plain text.
Can I use standard HTML tags like <b> in the calculated field?
No, standard PDF JavaScript for calculated fields does not parse HTML tags directly within event.value. You must utilize the event.richValue array property along with specific styling objects to format text dynamically.
How do I change the text color along with the font weight?
You can add a textColor property to the specific text object inside your event.richValue array. For instance, using {text: "Important:", fontWeight: 800, textColor: ["RGB", 1, 0, 0]} will make that portion of the text both bold and red.
Is it possible to use event.richValue on non-calculated fields?
Yes, event.richValue can be used via custom format scripts or custom keystroke scripts to dynamically format user inputs, provided that the target text field has Rich Text Formatting enabled.




