Other PDF Issues

How to Remove Trailing Spaces from Excel Values in Acrobat PDF Forms

Nimra MalikNimra Malik Nov 5, 2026 870 views

Question details

The user needs to remove leading and trailing spaces from values copied from Excel into Acrobat PDF forms so that JavaScript drop-down conditions can properly match the codes.

How to Remove Trailing Spaces from Excel Values in Acrobat PDF Forms
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Pasting data copied from Microsoft Excel into an interactive Acrobat PDF form field.
Observed behavior
Invisible leading or trailing spaces included in the pasted Excel values prevent the existing Acrobat JavaScript logic from successfully matching and recognizing the drop-down codes.
Before you start

Ensure you have the 'Prepare Form' tool enabled in your PDF editor and possess the necessary permissions to edit JavaScript properties for the form fields.

Solution 1Recommended

Use a Custom JavaScript Validation Script

Apply a regular expression script to the form field to automatically clean up and trim any whitespace from the pasted Excel values.

When you copy cells from Excel, invisible whitespace characters or line breaks are often included in the clipboard. Adding a custom validation script ensures that your PDF form automatically cleans the input before evaluating any conditional logic or drop-down matching.

1
Open Prepare Form Mode

Open your document in Adobe Acrobat, navigate to the 'Tools' menu, and select the 'Prepare Form' option to access the interactive fields.

2
Access Field Properties

Right-click on the specific form field where you will paste the Excel values, and select 'Properties' from the context menu.

3
Navigate to the Validate Tab

In the Field Properties dialog box, click on the 'Validate' tab to set up input rules.

4
Enable Custom Scripting

Select the 'Run custom validation script' radio button and click the 'Edit' button to open the JavaScript editor.

5
Enter the JavaScript Code

Type or paste the following code into the editor: event.value = event.value.replace(/^\s+/, "").replace(/\s+$/, ""); then click 'OK' to save and close the properties.

Use a Custom JavaScript Validation Script
Validation Successful: This script will now automatically trim the pasted value, keeping the stored field clean and allowing your existing conditions to correctly recognize codes.
Seamlessly Manage PDFs and Spreadsheets

Edit PDFs and Spreadsheets Seamlessly with WPS Office

Avoid formatting mismatches and tedious scripting by using the unified WPS Office suite. With built-in tools for both Excel-compatible spreadsheets and advanced PDF editing, you can manage your data and fill forms smoothly in one lightweight application.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
  2. 2. Clean Data in WPS Spreadsheet: Launch your Excel data file directly within WPS. Use the built-in TRIM function to remove any trailing spaces before copying.
  3. 3. Fill PDF Forms Easily: Open your PDF document in WPS PDF, select the interactive form fields, and paste your clean data flawlessly.
Easily view, edit, and fill interactive PDF forms without complex external tools.High compatibility with Microsoft Excel (.xlsx) and Adobe PDF formats.Clean data handling between WPS Spreadsheets and WPS PDF minimizes hidden formatting spaces.All-in-one suite saves system resources and improves your document workflow.
microsoft office alternative - wps office

Frequently Asked Questions

Why do values copied from Excel have extra spaces?

Excel often includes a trailing tab or space character when copying cell data to the clipboard. This ensures proper column spacing when pasted into plain text editors but can break strict validation rules in PDF forms.

Can I remove the extra spaces directly in Excel before pasting?

Yes. You can use the TRIM() function in Excel to create a new column of data with removed leading and trailing spaces, then copy those cleaned values into your PDF form.

Will this JavaScript validation affect manual typing in the PDF form?

The script will automatically remove any accidental spaces placed at the beginning or end of manually typed entries as well, which helps maintain clean data without interfering with normal typing.

Does WPS PDF support filling out interactive PDF forms?

Yes, WPS PDF allows you to view, fill out, and interact with standard PDF forms, making it a great lightweight alternative for handling document workflows and data entry.