PDF Editing Issues

How to Remove the PDF Extension from a File Name in Acrobat Forms

Aamir Naveed AkramAamir Naveed Akram Nov 5, 2026 869 views

Question details

The user needs to display the current PDF document's name inside a form field but wants to automatically exclude the .pdf extension from the visible text.

How to Remove the PDF Extension from a File Name in an Acrobat Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Automatically populating a text field with the document's file name using a custom JavaScript calculation.
Observed behavior
By default, the documentFileName property returns the full file name including the .pdf extension, which requires an additional script to strip away.
Before you start

Ensure you are using a PDF editor that supports form editing and JavaScript execution. You may also need to enable JavaScript in your software preferences to properly test the script.

Solution 1Recommended

Use JavaScript with a Case-Insensitive Regular Expression

Apply a JavaScript regex replacement to securely and cleanly strip the extension regardless of its capitalization.

When working with Acrobat forms, the documentFileName property fetches the complete name of the file. By utilizing the replace() method combined with a regular expression, you can target the .pdf portion at the very end of the string and replace it with an empty string.

Using a case-insensitive regular expression ensures that the script works perfectly even if the file is saved as .PDF or .Pdf.

1
Open the Form Field Properties

In Prepare Form mode, right-click the target text field (for example, 'Text1') where you want the file name to appear, and select 'Properties'.

2
Navigate to the Calculate Tab

Click on the 'Calculate' tab located in the Properties window and select the 'Custom calculation script' option.

3
Enter the JavaScript Code

Click the 'Edit' button and input the following script: this.getField("Text1").value = this.documentFileName.replace(/\.pdf$/i, "");

4
Save and Test Your Form

Click 'OK', close the properties dialog box, and save the document. The text field should now populate with the file name minus the .pdf extension.

Understanding the Regular Expression: In the script, the /\.pdf$/i code searches for '.pdf' strictly at the end of the string (denoted by the $ sign), while the 'i' makes the search case-insensitive.
Efficient PDF Editing

Easily Manage and Edit PDF Forms with WPS Office

If you need a reliable and intuitive solution for handling PDF forms, WPS Office provides a comprehensive PDF editor. You can view, fill out, and manage interactive PDF documents effortlessly without worrying about complex scripting.

  1. 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF form you wish to edit or fill out.
  2. 2. Access the Form Tools: Navigate to the 'Form' tab on the top ribbon to view available interactive field options.
  3. 3. Modify Form Properties: Double-click any form field to open its properties menu, where you can adjust text formatting, defaults, and appearance.
  4. 4. Save and Export: Click 'Save' to apply your modifications, ensuring full compatibility and easy sharing across different PDF viewers.
Easily fill, edit, and manage interactive PDF forms.Highly compatible with standard Adobe Acrobat PDF formats.Lightweight software with an intuitive, user-friendly interface.Includes a full suite of tools for handling Word, Excel, PowerPoint, and PDF files.
QA img-9

Frequently Asked Questions

Why is my JavaScript calculation not updating the field automatically?

Calculations typically trigger when a form value changes. If the script relies purely on the document opening, you may need to apply the script as a 'Page Open' action rather than a custom calculation script to ensure it triggers immediately.

Will this script remove the extension if it is saved in uppercase (.PDF)?

Yes. The 'i' flag at the end of the regular expression ( /\.pdf$/i ) ensures that the search is case-insensitive, meaning it will successfully remove .pdf, .PDF, or .Pdf.

Can I extract just the file name without the full computer file path?

Yes. The documentFileName property natively returns only the base file name (e.g., 'invoice.pdf'), not the full directory path. Stripping the extension is all that is required to isolate the name itself.