PDF Editing Issues

How to Extract the First Three Characters from a PDF Form Field

Bushra ParveenBushra Parveen Nov 2, 2026 869 views

Question details

The user needs to automatically copy a specific substring (the first three characters) from one PDF form field into a destination field.

How to Extract the First Three Characters from a PDF Form Field
Product
PDF Editor
Device & OS
not provided
Scenario
Setting up a dynamic PDF form where specific fields are auto-populated based on the inputs from other text fields.
Observed behavior
The destination field requires an automated script to extract and display characters like 'SMI' from a source field containing 'SMITH'.
Before you start

Verify the exact name of your source field (e.g., 'Last Name'), as field references in PDF scripts are strictly case-sensitive and must account for spaces.

Solution 1Recommended

Apply a Custom Calculation Script

Use a simple JavaScript substring method in the destination field's properties to pull the first three characters from the source field.

PDF forms support JavaScript for field calculations. By targeting the source field and using the substr() method, you can extract any specific portion of a text string.

1
Access Field Properties

Right-click the destination field where the extracted characters should appear, and select 'Properties' from the context menu.

2
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab to view the calculation options.

3
Enable Custom Scripting

Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor.

4
Enter the Substring Script

Type the following code: event.value = this.getField("Last Name").valueAsString.substr(0,3); Make sure to replace "Last Name" with the exact name of your source field.

5
Save and Test

Click 'OK', then 'Close'. Preview your PDF form and type a word into the source field to verify the destination field updates automatically.

Apply a Custom Calculation Script
Exact Matching Required: The field name inside the getField() method must perfectly match the actual source field name, including any capitalization and spaces.
Professional PDF Editor

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides an intuitive suite of PDF editing tools, allowing you to easily create, format, and manage interactive PDF forms with full support for JavaScript calculations.

  1. 1. Open PDF Document: Launch WPS Office and open your PDF file using the PDF editor.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form creation tools.
  3. 3. Edit Field Properties: Double-click any text field to access its properties, where you can easily configure custom calculations and actions.
Easily add text fields, checkboxes, and drop-down menus to PDF forms.Fully compatible with standard Adobe PDF formats and JavaScript automated calculations.Lightweight and fast editing experience on both desktop and mobile devices.
microsoft office alternative - wps office

Frequently Asked Questions

How can I extract characters from the end of a field instead of the beginning?

To extract characters from the end of a string, you can use the slice() method with a negative index in your JavaScript. For example, replace .substr(0,3) with .slice(-3) to get the last three characters.

Why isn't my destination field updating when I type in the source field?

The source field must be configured to commit its value immediately. Right-click the source field, go to Properties > Options, and check the box for 'Commit selected value immediately'.

Does this JavaScript calculation work on mobile PDF viewers?

Advanced JavaScript calculations in PDF forms are generally supported on robust desktop editors like WPS Office or Adobe Acrobat. Basic mobile viewers may not execute custom scripts, causing the fields to remain blank.