PDF Editing Issues

How to Extract or Trim the First Character of a PDF Field in Acrobat

Chanuka GeekiyanageChanuka Geekiyanage Nov 24, 2026 868 views

Question details

The user needs a JavaScript custom calculation to extract or left-trim the first character of a text field named 'Test Left' in Adobe Acrobat.

How to Extract or Trim the First Character of a PDF Field Using JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating interactive PDF forms requiring text formatting or extraction using JavaScript.
Observed behavior
The user wants to display the modified string in a calculation field and needs to confirm if spaces are permitted within field names.
Before you start

Ensure you are in Adobe Acrobat's Prepare Form mode and have the exact name of the source text field you want to reference in your calculation.

Solution 1Recommended

Extract the First Character Using JavaScript

Use the substring method in a custom calculation script to retrieve and display only the first character of your target text field.

In Adobe Acrobat, you can use JavaScript's native string methods to manipulate field values. The substring(0, 1) function starts at the very beginning of the string (index 0) and stops before index 1, effectively extracting just the first character.

1
Open Field Properties

Right-click the destination calculation field in Prepare Form mode and select 'Properties'.

2
Navigate to Calculate Tab

Go to the 'Calculate' tab in the Text Field Properties dialog box and select the 'Custom calculation script' option.

3
Enter the JavaScript Code

Click the 'Edit' button and enter the following script: event.value = this.getField("Test Left").valueAsString.substring(0, 1);

4
Apply and Save

Click 'OK' to save the script, then click 'Close' to apply the properties to your field.

Extract the First Character Using JavaScript
Free Microsoft Office alternative

Manage PDFs and Office Documents Effortlessly with WPS Office

While advanced JavaScript calculation for forms is specific to Adobe Acrobat, WPS Office provides a comprehensive, lightweight, and free PDF editor alongside its powerful Word, Excel, and PowerPoint alternatives. Easily read, annotate, fill out standard forms, and convert PDFs seamlessly.

Lightweight and feature-rich free PDF editorHigh compatibility with standard PDF formats and Microsoft Office filesSeamlessly edit PDF text, images, and standard form fieldsFamiliar, easy-to-use user interface for effortless migration
microsoft office alternative - wps office

Frequently Asked Questions

Can I use spaces in Adobe Acrobat PDF field names?

Yes, spaces are fully supported in Adobe Acrobat field names. When referencing them in JavaScript, simply wrap the exact field name, including the spaces, in quotation marks, such as this.getField("Test Left").

What is the difference between substring() and substr() in Acrobat JavaScript?

The substring(startIndex, endIndex) method extracts characters between two specified index points. The substr(startIndex, length) method extracts a specific number of characters starting from the given index. Both methods are valid in Acrobat JavaScript.

Why is my custom calculation script not updating immediately when I type?

By default, Acrobat fields do not commit values immediately upon typing. To fix this, open the properties of the source field (e.g., 'Test Left'), go to the 'Options' tab, and check 'Commit selected value immediately'.

How do I ensure a blank field doesn't trigger a calculation error?

You can add a simple if-statement to check if the source field is empty before running the substring extraction. For example: if (this.getField("Test Left").valueAsString !== "") { event.value = ... } else { event.value = ""; }