Other PDF Issues

Fix Acrobat JavaScript SaveAs Not Working from a Button

John WilsonJohn Wilson Nov 3, 2026 868 views

Question details

The user is attempting to save a PDF file automatically using a JavaScript saveAs method triggered from a form button, but the operation fails to execute.

How to Fix Acrobat JavaScript SaveAs Not Working from a Form Button
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form and using a custom button to trigger a file-saving operation via JavaScript.
Observed behavior
The saveAs method fails when executed directly from the form button due to security restrictions requiring a privileged or trusted context.
Before you start

Ensure you have administrative privileges on your computer, as you will need to create and save folder-level JavaScript files in the application's installation directory.

Solution 1Recommended

Create a Trusted Function for the SaveAs Operation

Bypass document-level security restrictions by defining a trusted function in a local folder-level script, which grants the necessary privileges for the saveAs action.

For security reasons, Acrobat prevents document-level scripts (like those attached to form buttons) from silently saving files to the user's hard drive. To perform a saveAs operation via a button, you must wrap the command in a trusted function located in a folder-level JavaScript file (.js) on the local machine.

1
Locate the JavaScript folder

Open the Acrobat JavaScript Debugger Console (Ctrl+J or Cmd+J) and type app.getPath('user', 'javascript') or app.getPath('app', 'javascript') to find the exact directory path for your scripts.

2
Create the folder-level script

Navigate to the identified folder, create a new text file named customSave.js, and open it with a text editor.

3
Define the trusted function

Add the following code to the file: var mySaveAs = app.trustedFunction(function(doc, path) { app.beginPriv(); doc.saveAs(path); app.endPriv(); }); and save the file.

4
Restart the application

Close and reopen Adobe Acrobat to allow the software to load your newly created folder-level script.

5
Execute from the form button

Open your PDF form, edit the JavaScript action of your button, and call the function by typing: mySaveAs(this, '/c/temp/myfilename.pdf'); ensuring you use the correct device path syntax.

Create a Trusted Function for the SaveAs Operation
Deployment Requirement: This folder-level script must be manually installed on every user's computer who interacts with the form. It cannot be embedded directly inside the PDF document itself.
Free Microsoft Office alternative

Discover a Simpler Way to Manage PDFs with WPS Office

If dealing with complex JavaScript trusted functions and deployment issues is slowing down your workflow, consider using WPS Office. It provides an intuitive, lightweight, and powerful PDF editor alongside its comprehensive suite of office tools.

Fully compatible with standard PDF forms and Microsoft Office formats (Word, Excel, PowerPoint)Intuitive graphical interface for saving, extracting, and managing PDF files without complex scriptingLightweight application that utilizes fewer system resources for faster loading timesSeamlessly transition from other PDF software with a familiar UI and built-in form-filling features
QA img-9

Frequently Asked Questions

Why does the saveAs JavaScript command work in the console but not from a button?

The JavaScript debugger console operates in a privileged context, allowing unrestricted execution of security-sensitive methods like saveAs. However, a form button runs at the document level, which is strictly restricted to protect users from malicious automated scripts.

Can I use saveAs without installing folder-level scripts on every user's computer?

No. If you are exclusively using the JavaScript saveAs method, security restrictions mandate that the trusted function resides in a folder-level script installed locally on each machine utilizing the form.

Does the saveAs method support saving to different file formats?

Yes, the saveAs method can export the PDF to different formats (such as text, HTML, or images) by specifying the appropriate conversion ID (cConvID) in the script parameters, provided the system has the corresponding export filters installed.

What happens if a user clicks the button without the trusted function installed?

The script will fail to execute, and the user will typically see a NotAllowedError in the JavaScript console stating that the security settings prevent access to the saveAs property or method.