Prevent Adobe Acrobat JavaScript from Overwriting Duplicate Files
Question details
The user needs to save completed PDF forms to a shared drive without overwriting files that have the same generated name.

- Product
- Adobe Acrobat JavaScript
- Device & OS
- not provided
- Scenario
- A PDF form builds its output filename from form fields and saves completed copies to a shared drive.
- Observed behavior
- When a filename already exists, selecting No in the overwrite prompt prevents the save but produces a JavaScript security error.
Confirm that users can write to the shared folder and identify the form script that calls saveAs. Check whether the save operation requires a trusted Acrobat JavaScript function in your environment.
Prompt before overwriting and handle the save error
Use the overwrite prompt to let users protect an existing file, then handle an unsuccessful save in the script.
In Acrobat, open the form's save button action or other JavaScript action that calls saveAs.
Set the saveAs parameter bPromptToOverwrite to true so Acrobat asks before replacing an existing file.
Wrap the saveAs call in a try/catch block. In the catch block, tell the user that the file was not saved and offer a way to choose or generate another name; retain error details for troubleshooting.
Save a form using an existing filename, select No in the overwrite prompt, and confirm that the original file remains unchanged and the user receives a clear message.

Generate a unique filename with a trusted save workflow
Use a managed workflow to choose a different name, such as one ending in (2), before saving.
Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility helps you move between common files, although it does not fix Acrobat JavaScript save errors.

Frequently Asked Questions
Does selecting No in the overwrite prompt save the form under another name?
No. Selecting No prevents that overwrite, but the script must provide another filename and retry the save if the user wants to keep a completed copy.
How do I make Acrobat ask before replacing a file?
In the JavaScript action that calls saveAs, set bPromptToOverwrite to true. Test it with a filename that already exists.
Why does the form still show a security error after I decline the overwrite?
The unsuccessful save can raise a JavaScript exception. Wrap saveAs in try/catch and check the error details, because permissions, paths, and Acrobat security restrictions can also cause failures.
Is checking for an existing file enough when several people save at once?
Not necessarily. Two users can check the same name before either saves. Use a managed component that reserves filenames atomically when concurrent saves are possible.
Can WPS Office fix the Acrobat JavaScript error?
No. The error belongs to the Acrobat JavaScript workflow. WPS Office is an alternative for working with PDFs and Office files, but the Acrobat script and its permissions must be addressed in Acrobat.




