Fix Acrobat JavaScript SaveAs Not Working from a Button
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.

- 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.
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.
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.
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.
Navigate to the identified folder, create a new text file named customSave.js, and open it with a text editor.
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.
Close and reopen Adobe Acrobat to allow the software to load your newly created folder-level script.
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.

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.

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.




