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

New Here ,
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

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.

TOPICS
Acrobat SDK and JavaScript, General troubleshooting, Standards and accessibility

Views

498

Likes

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

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

New Here ,
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

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.

TOPICS
Acrobat SDK and JavaScript, General troubleshooting, Standards and accessibility

Views

499

Likes

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
Mar 02, 2020 0
New Here ,
Mar 02, 2020

Copy link to clipboard

Copied

I already contacted the site I got the original JavaScripts from

 

https://www.pdfscripting.com/public/Contact-Us.cfm

 

awaiting...

Likes

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
Reply
Loading...
Mar 02, 2020 0
Adobe Community Professional ,
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. 

 

 

 

Likes

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
Reply
Loading...
Mar 02, 2020 0
Explorer ,
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.

Likes

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
Reply
Loading...
Mar 02, 2020 0
Adobe Community Professional ,
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:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

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. 

Likes

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
Reply
Loading...
Mar 02, 2020 0
Explorer ,
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.

 

 

Likes

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
Reply
Loading...
Mar 02, 2020 0
Adobe Community Professional ,
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. 

 

Likes

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
Reply
Loading...
Mar 02, 2020 0
Explorer ,
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.

Likes

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
Reply
Loading...
Mar 02, 2020 0
New Here ,
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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Adobe Community Professional ,
Mar 03, 2020

Copy link to clipboard

Copied

Try the scripts with Acrobat Reader DC on Windows 10.

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
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).

Likes

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
Reply
Loading...
Mar 03, 2020 1
Adobe Community Professional ,
Mar 03, 2020

Copy link to clipboard

Copied

Can be a problem with version XI and Windows 10.

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
Mar 03, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
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: https://try67.blogspot.com/2012/07/acrobatreader-close-all-files.html

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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

 

 

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
New Here ,
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 ???

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Adobe Community Professional ,
Mar 03, 2020

Copy link to clipboard

Copied

@SoWhat and @1234sa

Thank you for doing the testing in the console. While I don't think you actually got what you were suppose to have done, you did get some traing on using this window.

 

Next, to move forward, run this code in the console window, and post the results. 

 

 

 

var len = app.activeDocs.length;
     for(var i=len-1;i>=0;i--)
     {
        oDoc = app.activeDocs[i];
   console.println("Path:" + oDoc.path);
        oDoc.saveAs(oDoc.path);
        oDoc.closeDoc(false);
     }

 

 

This is the same code as in the function. But the try/catch statements are removed and a console.println statement is inserted that will tell us something about each file before it is processed. 

Likes

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
Reply
Loading...
Mar 03, 2020 0
Explorer ,
Mar 03, 2020

Copy link to clipboard

Copied

SoWhat and 1234sa - same person - different accounts and locations. So on Win7 these are the latest updates - As @try67 correctly pointed out for @Thom_Parker 's code '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, so that's a big issue. Remove one script and then try it again'. Indeed when only one of the JS files is planted in the JS folder it runs perfectly on Win7. But as soon as both are planted the SaveAll takes precedence rendering CloseAll useless.

 

My question still stands - 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?

 

@Thom_Parker I ran the code you provide above, having in advance planted both JS in the folder. That is ofc if by running the code means opening the JS debugger with Ctrl+J, pasting your code in the console window, and right at the bottom pressing Ctrl+Enter. If that's not how you run it then maybe a 1-sentence long explanation wouldn't be bad. This is the result on Win7:

 

SyntaxError: syntax error
1:Console:Exec
undefined

Likes

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
Reply
Loading...
Mar 03, 2020 0
Adobe Community Professional ,
Mar 03, 2020

Copy link to clipboard

Copied

In the console press ctrl-a ctrl-enter.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Adobe Community Professional ,
Mar 03, 2020

Copy link to clipboard

Copied

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

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

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. 

 

 

Likes

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
Reply
Loading...
Mar 03, 2020 0
Explorer ,
Mar 03, 2020

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Mar 03, 2020 0
Most Valuable Participant ,
Mar 23, 2020

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Mar 23, 2020 0
Explorer ,
Mar 23, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 23, 2020 0
Explorer ,
Mar 23, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Mar 23, 2020 0
Explorer ,
Mar 23, 2020

Copy link to clipboard

Copied

This is beyond shame and audacity.

Likes

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
Reply
Loading...
Mar 23, 2020 0
Most Valuable Participant ,
Mar 23, 2020

Copy link to clipboard

Copied

Agreed. It's an absolute disgrace.

Likes

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
Reply
Loading...
Mar 23, 2020 0