How to Change PDF Form Field Font and Size with JavaScript
Question details
The user wants to change the font and text size of instructional text within a PDF form field using JavaScript.

- Product
- Device & OS
- not provided
- Scenario
- Customizing PDF form fields dynamically using JavaScript to display instructional text in a specific font and size.
- Observed behavior
- The user needs the correct JavaScript syntax to modify the textSize and textFont properties of a target form field, as standard CSS syntax does not work.
Ensure you have access to the JavaScript console or the form field properties in your PDF editor, and verify the internal name of the font you intend to use.
Use Acrobat JavaScript Properties to Set Font and Size
Apply the correct JavaScript properties (textSize and textFont) to the target field event to adjust the text appearance.
When assigning instructional text to a PDF form field, standard CSS-like syntax (such as font.size = "10pt";) will not work. Instead, you must use specific JavaScript API properties for the event target.
Right-click the target form field in your PDF editor and select 'Properties'.
Depending on when you want the text to change, go to the 'Actions' tab (for triggers like Mouse Enter/Exit) or the 'Calculate' tab for custom calculation scripts.
Select 'Run a JavaScript' and enter the code to set the text size. For example: event.target.textSize = 10;
Add the code to set the font using its internal name. For example: event.target.textFont = "Arial";

Edit PDF Forms Easily with WPS Office
If you prefer a more straightforward way to edit PDF form fields and text without writing JavaScript, WPS Office provides an intuitive PDF editor to customize text, fonts, and form properties visually.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your PDF document containing the form fields.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access form editing tools.
- 3. Edit Form Properties: Click on the form field you want to modify, and use the properties panel to adjust the font size and style visually.
- 4. Save the PDF: Once your adjustments are complete, save the document to preserve the new form field formatting.

Frequently Asked Questions
Why isn't font.size = '10pt' working in my PDF form?
PDF JavaScript uses a specific API for form fields. Standard CSS or HTML syntax like font.size is not recognized. You must use event.target.textSize instead.
How do I find the internal font name for PDF JavaScript?
Standard internal fonts include 'Helvetica', 'Times-Roman', 'Courier', 'Arial', and 'ZapfDingbats'. For custom fonts, you may need to check the document's font properties (File > Properties > Fonts) to see the exact embedded name.
Can I change the font color using JavaScript in a PDF?
Yes, you can change the text color using the textColor property, such as event.target.textColor = color.red; or by defining an RGB array like event.target.textColor = ["RGB", 1, 0, 0];.
Where do I place the JavaScript code for a PDF form field?
You can place the code in the field's properties under the 'Actions' tab (triggered by events like Mouse Up or On Blur) or in the 'Calculate' tab if the text changes dynamically based on other field values.




