How to Make a PDF Multiline Text Field Shrink Automatically
Question details
The user wants to configure a multiline text field in a PDF so that the font size starts large and automatically shrinks as more text is entered.

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where users might input varying lengths of text into a fixed-size multiline field.
- Observed behavior
- By default, text fields may not dynamically adjust font size based on text length, or the Auto setting starts with a smaller font than desired based on the field's physical height.
Ensure you have a PDF editor with form creation and JavaScript support, and verify that your target text field is set to allow multiline input in its properties.
Use Custom JavaScript to Adjust Font Size Based on Character Count
Apply a custom format script to the text field to dynamically reduce the font size when the text exceeds specific length thresholds.
While the 'Auto' font size setting relies on the field's height, a custom JavaScript allows you to start with a specific large font and shrink it progressively. Note that the text size will update when the user finishes typing and clicks outside the field (loses focus), rather than continuously while typing.
It is crucial to test the length thresholds in descending order in your script so that the conditions are evaluated correctly.
Open your PDF in form editing mode, right-click the multiline text field, and select Properties from the context menu.
Go to the Format tab and select Custom from the Select format category dropdown menu.
In the Custom Format Script window, enter a script that checks event.value.length in descending order. For example: if (event.value.length > 70) event.target.textSize = 11; else if (event.value.length > 55) event.target.textSize = 12; else if (event.value.length > 40) event.target.textSize = 13; else event.target.textSize = 14;
Click OK to save the script, close the properties dialog, and test the form field by typing text and clicking outside the box to see the font size adjust.

Enable the Auto Font Size Setting
Use the default Auto setting to let the PDF viewer manage the font size based on the field's physical height and text overflow.
Create and Edit Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily create, edit, and manage interactive PDF forms, including text fields, checkboxes, and more.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the Form tab in the top ribbon to access form creation tools.
- 3. Add a Text Field: Select Text Field and draw the field on your document where you want users to type.
- 4. Customize Properties: Right-click the newly created field, select Properties, and customize the appearance, multiline settings, and font size.

Frequently Asked Questions
Why doesn't the text shrink immediately while I am typing?
PDF viewers generally execute format scripts when the field loses focus (when you click outside of it). The text size will update once the user finishes typing and moves to the next field or clicks elsewhere on the page.
How does the Auto font size determine the starting text size?
The Auto setting calculates the initial font size based on the physical height of the text field box. For example, a field height of 0.41 cm typically starts with a font size of 8, while 0.58 cm starts at 12.
Can I apply this JavaScript to multiple text fields at once?
Yes, you can copy and paste the custom format script into the properties of each multiline text field. Alternatively, if you have many fields, you can create a document-level JavaScript function and call it from each field to apply the logic globally.




