Skip to main content
dj0691
Participating Frequently
December 10, 2019
Question

Close one of two files open

  • December 10, 2019
  • 2 replies
  • 537 views

I have code that clears out certain type of comments using an annots.destroy method and it then extracts pages to another file based on certain criteria.  I now have two files open - the original file and the extracted pages copy.  I'd like code to close the original file without saving any changes.  I've tried different placements of this.closeDoc(true) without success.  Tried using a variable in place of this and it did not like that either.  Any suggestions would be greatly appreciated...

This topic has been closed for replies.

2 replies

try67
Community Expert
December 12, 2019

Be aware that several versions of Acrobat DC have a bug in them where the closeDoc command dosen't work.

Thom Parker
Community Expert
December 10, 2019

So this script is a Folder level scirpt, or an Action script?

For these types of scripts, "this" is always the current document when the script was executed. So it should close the document that was current when the process was started. 

 

So where is your script located? and what is happening when the code is run? Are the any errors reported in the Console Window?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
dj0691
dj0691Author
Participating Frequently
December 11, 2019

Hi  - this is an Action script.  Doing the following:

1) Open the PDF using Acrobat Pro

2) Run Action/JavaScript stripping out highlight comments (annots.destroy where = highlights)

3) Create/extract a number of pages from the orig based on criteria - so now have two PDFs open - orig and copied/extracted version

4) Now want to close the orig and not save any changes so as to maintain the orginal comments

5) Placed this.closeDoc(true) as the last line of the code - Adobe errors out and stops working.

6) I then placed a delay around the close command such as 

            setTimeout(doTo,2000);
            function doTo(){
            this.closeDoc(true); }

that fixed the kick out issue but still leaves the orginal document open.

Thom Parker
Community Expert
December 11, 2019

You cannot explicitly close the original document in an Action Script, because this poses a conundrum. The document is being operated on  by the Action process. If you close it, then the process has an invalid pointer to the document and any following operations by the Action process will overwrite memory or cause some other horrible programming catastrophy. If the PDF is not open when the Action starts, then the Action will close it when it's done. If its open, then it will remain open. But either way, it is the Action that determines this. 

 

If you are operating on a single PDF at a time, then use a command. Or better yet, write a folder level script. But always be aware of the scripting context in which your code is operating. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often