Other PDF Issues

How to Close One of Two Open PDFs Using Acrobat JavaScript

Emma BrownEmma Brown Nov 2, 2026 868 views

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.

How to Close One of Two Open PDFs Using Acrobat JavaScript
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.
Before you start

Enable the JavaScript console in Acrobat before running your script so you can monitor for syntax or runtime errors during execution.

Solution 1Recommended

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.

1
Identify the script context

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.

2
Add the closeDoc command

Insert the command 'this.closeDoc(true);' at the appropriate point in your JavaScript code where the original document should be closed.

3
Test the script and check for errors

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.

Use the closeDoc Method on the Original Document Object
Acrobat DC Bug: Be aware that several versions of Adobe Acrobat DC have a known software bug that prevents the closeDoc command from functioning correctly. If your code is correct but fails, this bug may be the cause.

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. 1. Open the PDF: Launch WPS Office and open your original PDF document.
  2. 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. 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. 4. Discard Changes: Choose 'Do Not Save' when prompted, which safely closes the original file while keeping your newly extracted document open.
Easily extract specific PDF pages visually without scripting.Fully compatible with standard PDF formats and Adobe Acrobat files.Lightweight software with an intuitive, tabbed document interface.Free built-in tools for merging, splitting, and organizing PDFs.
microsoft office alternative - wps office

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.