Other PDF Issues

How to Copy or Move PDF Files to Another Folder Using Acrobat JavaScript

Huma Ashraf ChHuma Ashraf Ch Nov 24, 2026 869 views

Question details

The user wants to automate the process of sorting, copying, or moving PDF files into different directory folders based on specific text content using Acrobat JavaScript.

How to Copy or Move Files to Another Folder Using Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Automating PDF file organization and routing based on extracted text content.
Observed behavior
Acrobat JavaScript operates inside a strict security sandbox and cannot execute direct file-system 'copy' or 'move' commands without using a privileged context and programmatic saving methods.
Before you start

Ensure you have administrative access to your computer, as you will need to create and place a folder-level JavaScript file into the Acrobat installation directory to bypass standard sandbox security restrictions.

Solution 1Recommended

Use Trusted Functions and doc.saveAs() to Copy Files

Since direct file copying is restricted, you must use a trusted folder-level script to bypass the security sandbox, open the document programmatically, and save a copy to the new location.

Adobe Acrobat JavaScript operates within a strict security sandbox that prevents direct file-system manipulation commands like 'copy' or 'move'. Executing these commands from a standard document-level script will result in a security block.

To achieve file routing, you must construct a folder-level script (a .js file placed in the Acrobat application JavaScripts folder) that defines a trusted function. This function can use app.openDoc() to read the file and doc.saveAs() to write the copy into the target directory.

1
Locate the JavaScripts Directory

Navigate to your Acrobat JavaScripts folder on your system. On Windows, this is typically located at 'C:\Program Files\Adobe\Acrobat DC\Acrobat\JavaScripts'.

2
Create a Folder-Level Script

Create a new text file with a '.js' extension in this directory. Define a 'trustedFunction' inside this file to wrap your file manipulation code, allowing it to bypass standard document-level restrictions.

3
Programmatically Open the PDF

Within your trusted function, use the code 'var myDoc = app.openDoc("/c/source_folder/file.pdf");' to open the PDF you want to copy.

4
Save a Copy to the Target Folder

Use the 'saveAs' method to write the file to its new destination: 'myDoc.saveAs("/c/target_folder/newfile.pdf");'.

5
Close the Document

Release the file from memory by calling 'myDoc.closeDoc(true);' after the copy has been successfully saved.

Use Trusted Functions and doc.saveAs() to Copy Files
Security Context Requirement: The doc.saveAs() method requires a privileged context. It will fail with a security exception if executed from a standard document-level script without a trusted function wrapper.
Free Microsoft Office alternative

Manage and Edit PDF Documents Easily with WPS Office

While Adobe Acrobat requires complex JavaScript configurations and privileged context setups for automated file routing, WPS Office provides an intuitive, user-friendly toolkit. As a powerful free Microsoft Office alternative, it allows you to easily edit, organize, split, merge, and save PDFs with full format compatibility and zero coding required.

  1. 1. Open WPS PDF: Launch WPS Office and click on the 'PDF' tab to access the dedicated PDF editor and management tools.
  2. 2. Edit or Split the PDF: Use the 'Edit' or 'Page' tools to manipulate your document's content, or use the 'Split PDF' feature if you need to separate pages into distinct files based on content.
  3. 3. Save to a New Location: Click 'Menu' and select 'Save As' to securely output the newly organized PDF to your preferred folder directory.
Easily split, merge, and organize PDF documents without relying on complex JavaScript APIs.Fully compatible with Microsoft Office formats (Word, Excel, PowerPoint) and standard Adobe PDFs.Lightweight architecture ensures smooth performance on older or restricted hardware environments.Familiar ribbon interface allows for an instant and seamless transition from other Office suites.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Acrobat JavaScript throw a security error when using the saveAs command?

Acrobat's security sandbox explicitly restricts document-level scripts from arbitrarily accessing the local file system to prevent malicious behavior. To resolve this, the 'saveAs' method must be executed within a privileged context via a folder-level trusted function.

Is there a native 'move' command in Acrobat JavaScript instead of copying?

No, Acrobat JavaScript does not have a native 'move' command for the file system. You must emulate a move operation by using 'doc.saveAs()' to create a copy in the new location, and then you may programmatically delete the original file if necessary.

How can I extract specific text from a PDF to determine where to save the file?

You can utilize the 'getPageNthWord()' method in Acrobat JavaScript. By iterating through the words on a specific page, you can search for a target string or reference number and dynamically concatenate it into the folder path string used in your 'saveAs' function.