PDF Editing Issues

How to Prompt Before Overwriting a File with Acrobat JavaScript

Chanuka GeekiyanageChanuka Geekiyanage Nov 2, 2026 870 views

Question details

The user needs to save a PDF file using Acrobat JavaScript with a generated filename, while ensuring a warning prompt appears if a file with the same name already exists.

How to Prompt Before Overwriting a File with Acrobat JavaScript
Product
Adobe Acrobat / PDF Editor
Device & OS
not provided
Scenario
Automating PDF saving using JavaScript where filename conflicts might occur.
Observed behavior
The user wants a confirmation dialog to prevent accidental overwriting of existing PDF files during an automated save process.
Before you start

Ensure you have administrative access to your computer, as you will need permission to create and configure folder-level JavaScript files in your PDF application's installation directory.

Solution 1Recommended

Configure saveAs Options in a Privileged Context

Use the saveAs method with the bPromptToOverwrite property enabled within a folder-level trusted script.

To prompt users before overwriting a file, you must pass an options object to the saveAs method with the 'bPromptToOverwrite' parameter set to true.

Crucially, security restrictions prevent trusted functions from being defined directly inside a document-level script or form button. The script must be placed in a privileged context, such as a folder-level JavaScript file.

1
Create a Folder-Level Script

Navigate to the JavaScripts folder of your Acrobat installation and create a new .js file using a plain text editor.

2
Define a Trusted Function

Inside the .js file, define a trusted function using app.trustedFunction. This function will wrap your save operation to grant it the necessary system privileges.

3
Implement the saveAs Method

Within your trusted function, insert the save code: doc.saveAs({cPath: filePath, bPromptToOverwrite: true});. This ensures the user is warned if the target filename already exists.

4
Call the Function from Your Form Button

In your PDF form, edit the button's JavaScript action to call the trusted function you defined in the folder-level script, passing the current document object as a parameter.

Privilege Requirement: If you cannot set up a folder-level script due to IT restrictions, you will not be able to automate the saving process due to built-in security protections.
Free Microsoft Office alternative

Try WPS Office for Comprehensive PDF Editing

While advanced Acrobat automation requires complex folder-level scripting, WPS Office provides an intuitive, lightweight, and fully-featured PDF editor alongside its Word, Excel, and PowerPoint alternatives. It simplifies your document workflow without unnecessary complexity.

  1. 1. Download WPS Office: Visit the official WPS website to download the free installer for your operating system.
  2. 2. Install the Application: Run the setup file and follow the on-screen instructions to install the comprehensive office suite.
  3. 3. Open and Edit PDFs: Launch WPS Office, select the PDF module, and open your files to start reading, annotating, or editing immediately.
Highly compatible with standard PDF, DOCX, XLSX, and PPTX formats.Lightweight and runs smoothly on all major operating systems.User-friendly PDF editor for annotating, signing, and managing pages easily.Free to download and use with a familiar, intuitive interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't my saveAs script work when placed directly in a form button?

For security reasons, PDF applications restrict scripts from silently writing to the local file system. The saveAs method requires a privileged context, meaning it must be executed from a trusted folder-level script rather than a standard document-level or button script.

What happens if I set bPromptToOverwrite to false?

If bPromptToOverwrite is set to false (or omitted entirely), the JavaScript saveAs method may automatically overwrite any existing file with the same name without displaying a warning dialog, which could lead to accidental data loss.

Where do I place folder-level JavaScript files?

Folder-level scripts are typically placed in the application's JavaScripts directory. The exact path depends on your operating system and the specific PDF software, but on Windows, it is often found in the Program Files directory under the application's installation folder.