'Acrobat Javascript closeDoc - Why does this.closeDoc close not only main document but also other document?

I have tried to control adobe acrobat using Action wizard Javascript. I want to open other document(PDF) and close previous document(PDF) opened. My code works well, but there is problem.

After open other document and close previous document, it closes other document which is opened just ago also.

would give me any advice ?

"test.pdf" file is main opened document which includes action wizard

and here code is,

this.saveAs("/C/" + "test_1.pdf");
this.closeDoc(true);

app.openDoc("/C/" + "test.pdf");


Solution 1:[1]

All that is missing is to create a variable reference to the document that needs closing, to tell Acrobat which document to close. The keyword "this" refers to the currently open document.

Answer adapted from Page 47, of the Acrobat JavaScripting Guide: https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsdevguide.pdf

// Example: Creating a new document from two other documents
var newDoc = app.newDoc(); // Creates a new PDF document
newDoc.insertPages({ nPage: -1, cPath: "/c/temp/doc1.pdf", }); // Insert doc1.pdf
newDoc.insertPages({ nPage: newDoc.numPages-1, cPath: "/c/temp/doc2.pdf", }); // Insert doc2.pdf
newDoc.saveAs({ cPath: "/c/temp/myNewDoc.pdf"; }); // Save the new document
newDoc.closeDoc(true); // Close the new document without notifying the user

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aRealPerson