• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

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:

Save All PDFs = Alt+F+F.jpg

 

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:

An internal error occurredAn internal error occurred

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

TOPICS
Acrobat SDK and JavaScript

Views

5.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Mar 30, 2020 Mar 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 fo

...

Votes

Translate

Translate
New Here ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

I already contacted the site I got the original JavaScripts from

 

Contact Us

 

awaiting...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Hi and thank you for the reply Thom. Now that I've had the chance to test, the SaveAll works OK on Win7 but on Win10 it fails.

 

As to CloseAll - it fails both on 7 and 10 giving the ''An internal error occurred'' prompt.

 

I totally agree that the likelihood is that the code is solid and the error is within Acrobat .. that is what I'm seeking help with.

 

I am by for not an IT specialist so debugging and all this is foreign to me.

The "catch" block being empty and having to put a console.println in there so you know "if" and "what" errors occur - says nothing to me.

 

I did try with various files, so that rules out the files themselves being corrupted. I did try with files placed in various locations - one drive, another drive, different partitions wihin the drives and then also on a network location - still fails as described in the original post.

 

Summary of fails:

Win 7 - SaveAll works, Close all does not work, doesn't even give the 'An internal error occurred' prompt.

Win 10 - both SaveAll and CloseAll do not work - both give the 'An internal error occurred' prompt.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Unless you hire an expert, you are the one who is going to have to debug this. So you'll need to come up to speed on a couple of things, using the Acrobat Console Window, and JavaScript. 

You'll find a tutorial on the Console window here:

Introduction to Scripting in Acrobat

 

In fact, several of these videos will be helpful.

 

So, to start debug you'll need to see if any errors are reported in the console window. To do this you'll need to remove the try/catch, so the exceptions can make their way to the console  

Next, you need to determine whether it is the close or save this is causing the issue.  Or if it is a timing problem caused by the looping. Again, you'll be using the console. In this case, by running test code. 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

I'll dig into that. Thank you very much.

 

You're saying that I 'need to determine whether it is the close or save this is causing the issue'. I don't see it as either one or the other causing the issue. As I said, on 7 SaveAll works but CloseAll does not. On 10, both don't work. but the fact they don't doesn't make them dependent on each other. I'd imagine there is no reason why both the CloseAll and SaveAll should not be able to co-exist side by side. And similarly why if one is broken then it's just broken without affecting the other, which can work on its own. Correct me if I'm wrong.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Debugging is about finding out what's going wrong. The first part of that is determining what's actually going wrong. Just saying it doesn't work adds nothing to the solution. We need specifics, i.e. more information. 

To do this we start very simple and work into more complex scenarios. 

 

So first, lets rule out the individual operations that are taking place. It may seem like these are not an issue because one function works over the other, but that's only circumstantial. We need solid proof. 

Use the Console window to run the SaveAs and Close operations. Do them individually and together. Do they operate as expected? Are any error conditions displayed?  

Once you do this you can move onto more complex testing. 

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 02, 2020 Mar 02, 2020

Copy link to clipboard

Copied

Thank you! On Win7x64, Acrobat XI I ran both codes in Console window. If I get it right - what I did is to paste the code in the console window and hit Ctrl+Enter right after last line of code. I get:


'undefined'

 

as output. I get it if it said that only for CloseAll but why with the SaveAll? SaveAll's menu button works fine. But running SaveAll's code from console gives 'undefined' and does NOT perform an actual save. It is only when pressing the file menu button that SaveAll actually works.

 

Running both codes together gives same error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Same result on Win10x64 - 'undefined' when I paste the both codes (separate and together) in Ctrl+J console window and hit Ctrl+Enter to run it. Am I doing this wrong?

 

I have reasons to think that it has to do with folder permissions because I'm not the admin on my work machine. When I'm copying the JS files to C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Javascripts I get this prompt

1.png

I hit Continue and it copies the files but still won't work. I did google the issue with folder permissions and checked under C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Javascripts - properties/security/advanced/owner - changed to my user instead of the office admin. The 2 *.js files CloseAll and SaveAll - I did the same with them so I'm the owner. Still doesn't run and gives the same error - An internal error occurred.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Try the scripts with Acrobat Reader DC on Windows 10.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

We do not use DC in our office and I personally don't use it on my home machine because it is horrific compared to the good old traditional Acrobat. So in both situations - DC is a no go.

 

As mentioned both java scrips used to work on W7.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Can be a problem with version XI and Windows 10.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Yes it is and that is why I'm posting here, seeking help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

Is this tread closed or something?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

"undefined" is not an error. The opposite, in fact. It means the code executed without errors (and without returning any values).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Perfect, that confirms what we've all known all along - that Thom's code is not at fault but something else is - either rights permissions to folders or something wrong with Acrobat XI ...

 

So, any suggestions as to the next steps for debugging? Save/CloseAll is a straightforward functionality requirement that a user does not have to go thru such pains for in order to get it to work - it's a paid software and something as simple as a button for SaveAll or CloseAll should just be built in the software by default ages ago.

 

Huge thanks to @Thom_Parker for even writing the code for this. Now to get the code to run - ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

These two scripts conflict with each other because they both contain a function with the same name (DoCloseAllDocs). However, in one script that functions saves the files and in another it closes them (without saving), so that's a big issue. Remove one script and then try it again.

 

If you're interested I also created a tool that does the same thing, but without this conflict, and it's also free. I just updated it to have an option to automatically save all the files before closing them, too.

You can find it here: Acrobat/Reader -- Close All Files With or Without Saving (FREE)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

100% correct as @try67  explained. Currently on Win 10. Here's the status:

 

1. When I remove the SaveAll and leave only the CloseAll in the folder for javascripts then the menu button works perfectly and it DOES prompt to save before closing (if any changes were made ofc).

 

2. When I then delete CloseAll and plant SaveAll in same folder, it once again gives the same annoying error - An internal error occurred. I immediately looked under the console and it says the following:

 

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.
Doc.saveAs:39:Menu Save All PD&Fs:Exec

 

I then pasted the SaveAll code in console and ran it - it gave 'undefined' again.

 

3. Worth to mention that for some reason now I cannot get rid of the SaveAll button - even when I delete the all JS files from the JS folder, the menu button SaveAll still remains in Acrobat and still doesn't work i.e. - An internal error occurred when ran on multiple pdfs. However, when I plant the CloseAll JS file back to the JS folder - then in Acrobat I expectedly get the CloseAll button and the SaveAll one, which (as mentioned) I cannot get rid of. It is then that I discovered that running either one of those buttons performs a CLOSE ALL. So it's as if the pesky alien SaveAll that came from nowhere is actually a duplicate of CloseAll and it only works when the real CloseAll is planted in the JS folder. So weird.

 

try67  - now looking at your files. Thank you so much. Can you add the functionality to only perform a SaveAllOpenPDFs without closing them?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

@try67 - as to your files - the CloseAll works just fine. The Close (AND SAVE) All gives - same error as in OP - An internal error occurred and console says:

 

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.
Doc.saveAs:25:Menu CloseSaveAllFiles:Exec

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

Running the code from a Console won't do anything because all the code that actually does something is in functions. So in order for it to do something you would need to add a call to that function.

 

And if that error is from my code then there's an issue with the names of your files. Do they contain a comma, by any chance?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

'add a call to that function' - no idea how to / what that is ... 

 

'And if that error is from my code then there's an issue with the names of your files. Do they contain a comma, by any chance?' - I use the file you provide via the download link in the mail called - CloseAllFiles.js

 

As to Thom_Parker's files - they're called - SaveAllDocsMenuItem.js and CloseAllDocsMenuItem.js so no commas there either. But anyway, when I planted tru67's files in the JS folder I deleted Thom_Parker's ones so this should rule out any conflict.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

I was referring to the name of the PDF file, not the js file.

 

If you don't know how to call a function then you really should not be editing the code or trying to run it from the console.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

'I was referring to the name of the PDF file, not the js file' - no commas there either but underscore "_" and bracket "[" yes. So yes, indeed when I rename the files to e.g. 1.pdf 2.pdf etc. both functions of your code work. But again - that's kinda limited. Can your code be tweaked to allow for freedom of naming the files?

 

'If you don't know how to call a function then you really should not be editing the code or trying to run it from the console' - yes, that is why I, as a paying user, post here in the Adobe support forum and seek help from a) those I pay to and b) members like you and Thom, whom I'm thankful to.

 

As to what you said earlier - 'These two scripts conflict with each other because they both contain a function with the same name (DoCloseAllDocs)' - don't there exist 2 separate functions - one called DoCloseAllDocs and another (I'd assume) DoSaveAllDocs so then I just mod the SaveAll JS file and flip the DoCloseAllDocs to DoSaveAllDocs ???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

There are a set of characters that can't be used in file-names when saving using a script (including a comma, for some reason). There's nothing that can be done about it by us. However, square brackets and underscores should be allowed, so it's strange.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines