How to Remove Trailing Spaces from Excel Values in Acrobat PDF Forms
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.

- 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.
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.
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.
Open your document in Adobe Acrobat, navigate to the 'Tools' menu, and select the 'Prepare Form' option to access the interactive fields.
Right-click on the specific form field where you will paste the Excel values, and select 'Properties' from the context menu.
In the Field Properties dialog box, click on the 'Validate' tab to set up input rules.
Select the 'Run custom validation script' radio button and click the 'Edit' button to open the JavaScript editor.
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.

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. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
- 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. Fill PDF Forms Easily: Open your PDF document in WPS PDF, select the interactive form fields, and paste your clean data flawlessly.

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.




