How to Display a Full Name Without Extra Spaces in Acrobat PDF Forms
Question details
The user wants to combine multiple text fields (First Name, Middle Name, Last Name, Suffix) into a single Full Name field dynamically, ensuring no double spaces appear if a field like Middle Name is left blank.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or editing a dynamic PDF form where a complete name needs to be auto-populated based on individual text field inputs.
- Observed behavior
- Standard string concatenation scripts leave an extra blank space when an optional field is empty, resulting in an unpolished appearance in the final Full Name field.
Ensure your PDF form already contains distinct text fields for the first name, middle name, last name, and suffix, and note their exact field names as JavaScript is case-sensitive.
Use Array Push and Join in Custom Calculation Script
This method pushes only non-empty name fields into a JavaScript array and joins them with a single space, automatically preventing double spaces.
Using a standard string concatenation like combining values with a plus sign results in double spaces if a field is blank. Leveraging an array allows the script to filter out empty strings before joining the components together.
Open your PDF document in Adobe Acrobat, navigate to the Tools menu, and select Prepare Form to enter the form editing mode.
Right-click on the destination text field where you want the full name to appear, select Properties, and navigate to the Calculate tab.
Select 'Custom calculation script' and click the Edit button. Enter the code to declare your variables using getField("Field Name").valueAsString. Create an empty array, use if statements to push variables to the array only if they are not equal to "", and set event.value = arrayName.join(" ");.
Click OK to save the script, then close the Properties dialog. Click Preview at the top right to test your form by entering names with and without middle names or suffixes to confirm no extra spaces are generated.

Need a simpler way to manage documents and PDFs? Try WPS Office
If dealing with complex PDF JavaScript calculations and expensive software is slowing you down, WPS Office provides a lightweight, all-in-one suite to easily view, edit, and manage your PDFs, Word documents, and spreadsheets without the hassle.

Frequently Asked Questions
Why does my PDF form show a double space when the middle name is empty?
If you use basic string concatenation, the script adds the hardcoded space characters regardless of whether the middle name contains text. Using an array to check for empty fields before joining them resolves this issue entirely.
Can I apply this JavaScript method to combine addresses in Acrobat?
Yes. You can use the exact same array push and join method to combine street, city, state, and zip code fields into a single block, skipping any blank address lines by only pushing non-empty values.
Where do I add custom calculation scripts in Adobe Acrobat?
In the Prepare Form tool, double-click the target field to open its Properties dialog. Navigate to the Calculate tab, choose 'Custom calculation script' at the bottom, and click the Edit button to paste your JavaScript code.




