How to Close One of Two Open PDFs Using Acrobat JavaScript
Question details
The user needs to close the original PDF document without saving changes using Acrobat JavaScript after a script has extracted pages into a second, newly opened document.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Running a PDF folder-level or action script that opens an original document, extracts pages to create a second document, and leaves both open on the screen.
- Observed behavior
- The user is struggling to target and successfully close the original document without a save prompt when multiple Acrobat documents are open simultaneously.
Enable the JavaScript console in Acrobat before running your script so you can monitor for syntax or runtime errors during execution.
Use the closeDoc Method on the Original Document Object
Target the correct document object using 'this' and pass 'true' to the closeDoc method to bypass the save prompt.
In folder-level and action scripts, the keyword 'this' generally refers to the document that was active and current when the script was first executed.
By identifying the original document and applying the closeDoc method with a boolean parameter of true, you instruct the application to close the file and discard any unsaved modifications.
Determine whether you are using a folder-level script or an action script, as this dictates how the 'this' object behaves. Ensure it points to your original starting document.
Insert the command 'this.closeDoc(true);' at the appropriate point in your JavaScript code where the original document should be closed.
Execute the script and monitor the JavaScript console. If the original document remains open, check if an incorrect document object is being referenced after the page extraction.

Extract Pages and Manage PDFs Easily with WPS Office
Instead of writing complex JavaScript to manage multiple open documents, you can use WPS Office's built-in UI tools to extract pages into a new file and safely close the original document with a single click.
- 1. Open the PDF: Launch WPS Office and open your original PDF document.
- 2. Extract Pages: Navigate to the 'Page' tab on the top ribbon and select 'Extract Page' to pull the desired pages into a new, separate document.
- 3. Close the Original File: Once the new PDF is created, click the 'X' on the original document's tab at the top of the screen.
- 4. Discard Changes: Choose 'Do Not Save' when prompted, which safely closes the original file while keeping your newly extracted document open.

Frequently Asked Questions
Why is my Acrobat JavaScript closeDoc command not working?
This often occurs due to a known bug in certain versions of Acrobat DC where closeDoc fails to execute. It can also happen if the JavaScript console is reporting an error, or if 'this' is referencing the wrong document object.
How do I close a PDF without saving changes in JavaScript?
You can close a PDF without triggering a 'save changes' prompt by passing 'true' as the parameter to the closeDoc method, written exactly as: this.closeDoc(true);
What does the keyword 'this' refer to in a PDF action script?
In folder-level and action scripts, the keyword 'this' always refers to the document that was active or current when the script execution initially started.




