• 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.4K

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

Copy link to clipboard

Copied

How does a computer work - you give it 2 things - data and instructions what to do with this data. You're now giving me a single line of code:

 

 

console.println("Path:" + app.activeDocs[i].path);

 

 

For a person with no IT experience I need instructions as to what to do with this code. So far, all you've told me is to run code in Ctrl+J console. Therefore the only thing I can do is run this single line of code in console and result is:

 

 

ReferenceError: i is not defined
1:Console:Exec
undefined

 

 

I did this 2 times. Once withe the *.js file (containing your code of all 3 functions) placed under C:\Program Files (x86)\Adobe\Acrobat and then 2nd time having deleted the *.js file, driven by what you said 'you ran code in the console that defines a function that already exists. Don't Do That'. Both times the results were as above.

 

'I don't see the results of an actual file path in this thread' - the only code you provided, which results in paths' being displayed is this one

 

 

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);
     }

 

 

I ran it and replied Button to save/close all open PDF docs [An internal error occurred] the file path being /Z/- Desktop/1.pdf  ... that is the path of the file I had open. If you want to help me give me A) data, B) instructions what to do with those data.

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 23, 2020 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.

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, these is very smart. Could ADOBE care less?

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

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

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

This is beyond shame and audacity.

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 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

Agreed. It's an absolute disgrace.

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 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

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

@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.

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 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

@1234sa

It's in my original reply detailing this issue.

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

@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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

LATEST

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).

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