Skip to main content
Participating Frequently
March 2, 2020
Answered

Button to save/close all open PDF docs [An internal error occurred]

  • March 2, 2020
  • 9 replies
  • 14727 views

Hi. I am on Acrobat XI Pro 11.0.23 - it's what our office uses. Have Win10 and Win7 machines and we get the following issue. What we wanted is to achieve a way to:

 

1. Make a button to Close All Open PDF docs. Found a way here - https://www.pdfscripting.com/public/Free_Acrobat_Automation_Tools.cfm

 

2. I then modified the code so instead of close it performs a Save on all open docs. This I achieved with the code I posted here (user ''So What''😞

https://answers.acrobatusers.com/ViewQuestion.aspx?questionId=293479

 

Several years ago both of these approaches worked flawlessly on a Win7 machine but now on new machines and installs it doesn't. This is how the JavaScrip-based button(s) from the above links look like:

 

The problem now on is that when I hit either the Close All or Save All button, Acrobat throws a prompt - 'An internal error occurred' like this one:

I already tried a plethora of Google suggested solutions having to do with folder permissions and so on. No luck. If anyone has another way of achieving the Save/Close all open PDFs or a way to fix the issue I'm experiencing with my way then pls help. I'll post the code here just in case, but as I said it once worked flawlessly on Win7. Why now it stopped on 7 and 10 I don't know.

 

Code for SaveAllDocsMenuItem.js  :

//////////////////////////////////////////////////////
//
// Save All PDFs Menu Item for Acrobat/Reader
//
// Written by Thom Parker for www.acrobatusers.com
//
// Copyright 2011 by WindJack Solutions, Inc.
//
//////////////////////////////////////////////
// 
//  ** GENERAL INSTALLATION INSTRUCTIONS:
//
//  This Acrobat Automation Script will only work when 
//  placed in one of the Acrobat JavaScript Folders. Execute
//  the following code from the Acrobat JavaScript Console to find
//  the location of the JavaScript folders. 
//
//  To display the Acrobat JavaScript Console use Ctrl+J on 
//  Windows and Command+J on the Mac, does not work properly on newer Mac Books
//
//      app.getPath("user","javascript");
//
//      app.getPath("app","javascript");
//
//  You may place this script file in either one of the folders.
//  However, the "user" folder is shared by both Acrobat and Reader
//  Placing the file in the user folder will make the menu item 
//  availible to both Acrobat and Reader
//

///////
// Business logic for closing documents
//
var DoCloseAllDocs = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for (var i=len-1; i>=0; i--) {
        app.activeDocs[i].saveAs(app.activeDocs[i].path);
}
   app.endPriv();
});

///////
//  User Interface, places menu item on File menu
//
app.addMenuItem({cName:"Save All PD&Fs", 
                 cParent:"File", 
                 nPos:"Close", 
                 cExec:"DoCloseAllDocs()", 
                 cEnable:"event.rc = app.doc != null"
});


/////////////////////////
// 
//  Variations on the main script.  To use, replace the cExec
//  script in the "addMenuItem" fucntion to use the 
//  given trusted fucntion. 

var DoCloseAllDocs_NoSave = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for (var i=len-1; i>=0; i--) {
        app.activeDocs[i].saveAs(app.activeDocs[i].path);
}
   app.endPriv();
});

//  This variation will not work for documents in Reader
//  that do not have save rights, but it fails in a well
//  behaved manor
var DoCloseAndSaveAllDocs = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for(var i=len-1;i>=0;i--)
     {
        oDoc = app.activeDocs[i];
        try{
          oDoc.saveAs(oDoc.path);
        }catch(e){}
        oDoc.closeDoc(false);
     }
   app.endPriv();
});

 

Code for CloseAllDocsMenuItem.js  :

//////////////////////////////////////////////////////
//
// Close All PDFs Menu Item for Acrobat/Reader
//
// Written by Thom Parker for www.acrobatusers.com
//
// Copyright 2011 by WindJack Solutions, Inc.
//
//////////////////////////////////////////////
// 
//  ** GENERAL INSTALLATION INSTRUCTIONS:
//
//  This Acrobat Automation Script will only work when 
//  placed in one of the Acrobat JavaScript Folders. Execute
//  the following code from the Acrobat JavaScript Console to find
//  the location of the JavaScript folders. 
//
//  To display the Acrobat JavaScript Console use Ctrl+J on 
//  Windows and Command+J on the Mac, does not work properly on newer Mac Books
//
//      app.getPath("user","javascript");
//
//      app.getPath("app","javascript");
//
//  You may place this script file in either one of the folders.
//  However, the "user" folder is shared by both Acrobat and Reader
//  Placing the file in the user folder will make the menu item 
//  availible to both Acrobat and Reader
//

///////
// Business logic for closing documents
//
var DoCloseAllDocs = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for(var i=len-1;i>=0;i--)
        app.activeDocs[i].closeDoc(false);
   app.endPriv();
});

///////
//  User Interface, places menu item on File menu
//
app.addMenuItem({cName:"Close All PD&Fs", 
                 cParent:"File", 
                 nPos:"Close", 
                 cExec:"DoCloseAllDocs()", 
                 cEnable:"event.rc = app.doc != null"
});


/////////////////////////
// 
//  Variations on the main script.  To use, replace the cExec
//  script in the "addMenuItem" fucntion to use the 
//  given trusted fucntion. 

var DoCloseAllDocs_NoSave = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for(var i=len-1;i>=0;i--)
        app.activeDocs[i].closeDoc(true);
   app.endPriv();
});

//  This variation will not work for documents in Reader
//  that do not have save rights, but it fails in a well
//  behaved manor
var DoCloseAndSaveAllDocs = app.trustedFunction(function()
{
   app.beginPriv();
     var len = app.activeDocs.length;
     for(var i=len-1;i>=0;i--)
     {
        oDoc = app.activeDocs[i];
        try{
          oDoc.saveAs(oDoc.path);
        }catch(e){}
        oDoc.closeDoc(false);
     }
   app.endPriv();
});

 

Looking for help! 10x

This topic has been closed for replies.
Correct answer 1234sa

So from what I saw and learnt in this thread @Thom_Parker could not be bothered to give basic instructions as to what to do - i.e. give data and give instructions as to what to do with these data. He prolly figured everyone is an IT pro. Well, we ain't. We're mere paying customers. Nevermind, thanks Thom for at least trying. Next time realise that not everyone is in your field of coding or programming and instead of getting angry at ppl try to help them out 🙂 No hard feelings here. One thing for you to take from all this is that, as @try67 and I confirmed - one cannot use a JS in Acrobat XI to save/close files, whose names or paths contain a comma, sq bracket or anything like that. Other than this limitation the latest code from @try67 works just fine on both w7 and w10. This is as good as it'll get so thank you all.

9 replies

1234sa
Inspiring
March 23, 2020

@Thom_Parker and @try67 tried to help out but as we all remember it lead to nothing. The bottom line was that Thom suggested that one CAN have any symbol in the pdf path/file name, whereas try67 confirmed that there is no such thing, thereby commas are not allowed in the path/file name. We tested that on my Win7 and 10 Acrobat XI versions and it's confirmed. So far we did reach.

 

Any other progress we did not make.

1234sa
1234saCorrect answer
Inspiring
March 30, 2020

So from what I saw and learnt in this thread @Thom_Parker could not be bothered to give basic instructions as to what to do - i.e. give data and give instructions as to what to do with these data. He prolly figured everyone is an IT pro. Well, we ain't. We're mere paying customers. Nevermind, thanks Thom for at least trying. Next time realise that not everyone is in your field of coding or programming and instead of getting angry at ppl try to help them out 🙂 No hard feelings here. One thing for you to take from all this is that, as @try67 and I confirmed - one cannot use a JS in Acrobat XI to save/close files, whose names or paths contain a comma, sq bracket or anything like that. Other than this limitation the latest code from @try67 works just fine on both w7 and w10. This is as good as it'll get so thank you all.

try67
Community Expert
Community Expert
March 30, 2020

Small correction: You can close such files, but not save them (at least not using a name that contains these "forbidden" characters, either in the file name itself, or anywhere in its path).

try67
Community Expert
Community Expert
March 23, 2020

@1234sa

It's in my original reply detailing this issue.

1234sa
Inspiring
March 23, 2020

@try67 thank you for helping out, highly appreciated. Do you still have the email with the msg I initially sent today. Could you PM the contents to me pls.

try67
Community Expert
Community Expert
March 23, 2020
1234sa
Inspiring
March 23, 2020

This is beyond shame and audacity.

try67
Community Expert
Community Expert
March 23, 2020

Agreed. It's an absolute disgrace.

1234sa
Inspiring
March 23, 2020

I wonder if I should ask your office how much we're paying for license to Adobe.

1234sa
Inspiring
March 23, 2020

Wow, these is very smart. Could ADOBE care less?

try67
Community Expert
Community Expert
March 23, 2020

I just got an email that the following post has been sent by "1234sa":

<QUOTE>

 

Wow ... the admins made sure to clean up this tread. Very, very interesting. Why, if I may ask?

@Thom_Parker and @try67 tried to help out but as we all remember it lead to nothing. The bottom line was that Thom suggested that one CAN have any symbol in the pdf path/file name, whereas try67 confirmed that there is no such thing, thereby commas are not allowed in the path/file name. So far we did reach.

 

Any other progress we did not make, but why would the admins delete the messages here? What is the reason for that?

<END QUOTE>

This message itself is also missing.

 

The answer is most likely that it was not any admin. It's just a serious bug in this forum's software that is making replies dissappear. I've noticed it a while ago and have reported it several times in a private "back room" forum, to no avail.

I'm coming to the conclusion this forum system is broken beyond repair and this latest bug where messages actually disappear into thin air is too much for me. I believe it is caused when passing a certain threshold of replies, either by number or length, but it makes discussion here impossible. If you want you messages to be seen reply only to the top-level post.

Participating Frequently
March 2, 2020

I already contacted the site I got the original JavaScripts from

 

Contact Us

 

awaiting...

Thom Parker
Community Expert
Community Expert
March 2, 2020

There's nothing wrong with the code. It works perfectly fine for me on Windows 7. Except of coures that the "catch" block is empty. You really need to put a console.println in there so you know "if" and "what" errors occur. 

 

The error states its an internal Acrobat issue. So possibly a bug. Could be an issue with the specific files, or with the file locations, or the OS. What debug have you done? Did you check the console window? Have you run the code manually in the console? Experimented with different files and folder locations? 

 You 've posted a ton of text, but not much real information. Do some debug and let us know what you find.  But the likelihood is that the issue has nothing at all to do with JavaScript. 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
1234sa
Inspiring
March 3, 2020

You may want to re-watch video on using the console window

Introduction to Scripting in Acrobat

 

Just pressing Ctrl-Enter runs the line the cursor is on. 

To run more than one one you have to select all the lines. 

 

Also, as I'm sure you've already surmised, functions with the same name will overwrite one another. You only need one of the JS files since both define exactly the same functions, i.e. "DoCloseAllDocs" and  "DoCloseAndSaveAllDocs". What you need are more "app.addMenuItem" calls to setup the menu items. But this is not necessarily the issue with the failure. It's just getting your ducks in order.

 

Run the code and we'll see where it's failing. 

 

 


Thanks. On Win7, with both JS placed in JS folder, I ran your code the right way and it closed the 2 open pdfs I had and displayed this result immediately after your code:

 

 

Path:/Z/- Desktop/[name of pdf file].pdf
Path:/Z/- Desktop/[name of pdf file].pdf

undefined

 

 

Those are the paths of the PDFs I had opened.