Italicize Part of a Form Field in an Acrobat Script
Question details
The user wants a form script to italicize only part of the text placed in a field for one switch case.

- Product
- Adobe Acrobat forms
- Device & OS
- not provided
- Scenario
- A switch statement assigns different text to a form field, and the second case needs partial italic formatting.
- Observed behavior
- The desired field value contains both regular and italic text in the second case.
Confirm whether the PDF is a standard Acrobat form or a LiveCycle Designer/AEM XFA form, and identify the target field's name. The rich-text method below applies to supported Acrobat form fields, not XFA fields.
Use rich-text spans in an Acrobat form field
Use this approach for a standard Acrobat form when the target text field supports rich-text formatting.
A plain field value does not specify formatting for individual words. A rich-text value can contain separate spans with different formatting properties.
In Acrobat, open All tools > Prepare a form, double-click the target text field, and look under Options for Allow Rich Text Formatting. Enable it if available.
Open the action or field script containing the switch statement. In the second case, get the target field with this.getField("FieldName"), replacing FieldName with the actual field name.
In that case, assign a rich-text value instead of a plain string. For example: this.getField("FieldName").richValue = [{text: "Regular text "}, {text: "italic text", fontStyle: "italic"}, {text: " regular text"}]; Keep the case's break statement after the assignment.
Use Preview in Prepare a form, trigger the second case, and check that only the intended span is italic. Test the other cases as well, since a later assignment to the field can replace its formatting.

Edit PDF Content and Office Files with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and support for common Office formats, making it easy to move everyday document work. Its PDF editing tools can help with static text, but they do not replace Acrobat's form scripting.

Frequently Asked Questions
Can I italicize one word by assigning a plain string to the field?
A plain string does not carry separate formatting for individual words. In a supported Acrobat rich-text field, assign spans through the field's richValue property instead.
Where do I enable rich text for an Acrobat form field?
Open All tools > Prepare a form, double-click the text field, and check the Options tab for Allow Rich Text Formatting. The option depends on the field and form type.
Will the Acrobat richValue example work in a LiveCycle Designer form?
Do not assume it will. LiveCycle Designer and AEM XFA forms use different form and scripting technologies, so check the XFA field's supported rich-text methods.
What should I check if the italic text does not appear?
Confirm that rich-text formatting is enabled, the script targets the correct field, and the second switch case runs. Also check whether another script later assigns a plain value to the same field.




