How to Calculate Character Count in an Acrobat Fillable PDF Form
Question details
The user needs to automatically calculate the number of characters entered into a PDF form field to determine a total price based on a per-character rate.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive order form where the cost varies depending on the length of a personalized text field.
- Observed behavior
- Requires a custom script or method to read the length of a text field and output that number into a calculation field for billing purposes.
Ensure your PDF editing software supports custom JavaScript for form fields (such as Adobe Acrobat Pro) and make a note of the exact name of your personalization text field.
Use Custom JavaScript for Form Field Calculation
Apply a short JavaScript snippet to a read-only field to capture the character length of the target text field and use it in your pricing calculations.
PDF forms use JavaScript to handle advanced calculations that go beyond simple addition or multiplication. By utilizing the length property of a field's value, you can dynamically count characters as the user types.
Open your PDF document in form editing mode. Select the text box where users will type their personalization text, right-click it, and open its Properties. Note the exact field name (e.g., 'Personalization').
Add a new text field to the form to display the character count. Open its Properties, navigate to the 'Calculate' tab, and select 'Custom calculation script'.
Click the 'Edit' button and enter the following script: event.value = this.getField("Personalization").valueAsString.length; (ensure you replace 'Personalization' with your actual field name). Click OK to save.
Create a final text field for the Total Cost. In its Calculate tab, choose 'Value is the product of the following fields', and select your Character Count field and a hidden field containing your price per character (e.g., 0.50).

Easily Create and Edit Interactive PDF Forms with WPS PDF
WPS Office includes a robust PDF editor that simplifies the creation, management, and completion of fillable PDF forms. Whether you need to insert text fields, manage properties, or design a polished layout, WPS PDF offers a highly compatible and intuitive workspace.
- 1. Open your document in WPS PDF: Launch WPS Office and open your PDF file using the built-in PDF editor.
- 2. Access the Form features: Navigate to the 'Form' tab on the top ribbon to reveal the comprehensive suite of form creation and editing tools.
- 3. Insert form fields: Click on 'Text Field' or other interactive elements, then click on the document page to place them. Double-click any field to modify its properties, appearance, and logic.
- 4. Save and distribute: Once your layout is complete, save the document. The resulting PDF will remain interactive and highly compatible across major PDF viewers.

Frequently Asked Questions
Why does the character count not update immediately as I type?
In standard PDF form behavior, calculation scripts are typically triggered when a field loses focus. The character count and total cost will update as soon as the user clicks outside the text field or presses the Tab key.
Does the character count calculation include spaces and punctuation?
Yes. The standard 'valueAsString.length' property counts every keystroke entered into the field, including blank spaces, punctuation marks, and special symbols.
How can I exclude spaces from the character count?
To ignore spaces in the count, modify the custom calculation script to remove spaces before calculating the length: event.value = this.getField("Personalization").valueAsString.replace(/\s/g, "").length;
Will this calculation script work on mobile PDF readers?
While custom JavaScript calculations are fully functional in robust desktop applications like Adobe Acrobat and WPS Office, many basic default mobile PDF viewers or web browser extensions do not support advanced JavaScript execution.




