PDF Editing Issues

How to Make Part of a Calculated PDF Field Bold with JavaScript

Kushani NimanthikaKushani Nimanthika Nov 3, 2026 869 views

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.

How to Make Part of a Calculated PDF Field Bold with JavaScript
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.
Before you start

Ensure you are using a professional PDF editor that supports JavaScript form calculations and has options to enable Rich Text Formatting for form fields.

Solution 1Recommended

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.

1
Enable Rich Text Formatting

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'.

2
Access the Calculation Script

Switch to the 'Calculate' tab within the same Properties window. Select 'Custom calculation script' and click the 'Edit' button to open the JavaScript editor.

3
Write the Array Script

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"}]; }

4
Save and Test

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.

Use Rich Text Formatting and the event.richValue Property
Understanding Font Weight Values: In PDF rich text JavaScript, a fontWeight value of 800 typically renders the text as bold, whereas a value of 400 represents standard, unbolded text.
Professional PDF Editor

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. 1. Download WPS Office: Download and install WPS Office Free on your computer or mobile device.
  2. 2. Open Your PDF Document: Launch the WPS PDF tool and open the interactive PDF form you wish to edit.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access various form controls and editing options.
  4. 4. Customize and Save: Adjust your text fields, configure calculation properties, and save your fully customized PDF form.
Fully compatible with standard PDF form fields and interactive elements.Easily edit text, modify layouts, and adjust PDF form properties without hassle.Lightweight, fast alternative to heavy PDF editors with an intuitive interface.Provides seamless document management across Word, Excel, and PDF formats.
microsoft office alternative - wps office

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.