These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

automatic saving and closing All opened Pdfs in Acrobat with FolderScript

Gebhard
Registered: Jul 18 2011
Posts: 25
Answered

Hello Forum,
sometimes I´ve much files opened in Acrobat, so edit this files e.g. with Pitstop. It would be nice to save all the opened Files in Acrobat with closing them in one Folderscript. I made this two FolderScripts for saving and closing the files, but only one file is saved and/or closed by the time. I made some experience found in the forum:
1 first Folder sript for saving the files(It saves only one File):
var ProcessDocument1d = app.trustedFunction(function()
{
app.beginPriv();
// Build path root from current document.
// Split off the ".pdf" at the end (this is just one way it can be done)
var aPth = this.path.split(".");
aPth.pop();
var cPathRoot = aPth.join(".");
// Now run the extraction loop
for ( var i = 0; i < this.numPages; i++ )
this.saveAs({
nStart: i,
cPath: ""+this.path+""});
this.closeDoc(true);
}
)
app.endPriv();
//add the menu item
app.addMenuItem({
cName: "DoppelSeitenZuEinzelSeitenJS", // this is the internal name used for this menu item
cUser: "Alle in Acrobat geoeffneten Dokumente Speichern",// this is the label that is used to display the menu item
cParent: "WeitereTools", // this is the parent menu. The file menu would use "File"
cExec: "ProcessDocument1d()",// this is the JavaScript code to execute when this menu item is selected
cEnable: "event.rc = (event.target != null);", // when should this menu item be active?
nPos: 1
});
2 second Folderscript to close all opened Files in Acrobat:
var ProcessDocument1c = app.trustedFunction(function()
{
app.beginPriv();
// Build path root from current document.
// Split off the ".pdf" at the end (this is just one way it can be done)
var aPth = this.path.split(".");
aPth.pop();
var cPathRoot = aPth.join(".");
// Now run the extraction loop
for ( var i = 0; i < this.numPages; i++ )
this.saveAs({
nStart: i,
cPath: ""+this.path+""});
for(var i=app.activeDocs.length-1; i>=0; i--)
{
if(app.activeDocs[i]!=this)
app.activeDocs[i].closeDoc(true);
}
}
)
app.endPriv();
// add the menu item
app.addMenuItem({
cName: "DoppelSeitenZuEinzelSeitenJS", // this is the internal name used for this menu item
cUser: "Alle in Acrobat geoeffneten Dokumente Schliessen", // this is the label that is used to display the menu item
cParent: "WeitereTools", // this is the parent menu. The file menu would use "File"
cExec: "ProcessDocument1c()",// this is the JavaScript code to execute when this menu item is selected
cEnable: "event.rc = (event.target != null);", // when should this menu item be active?
nPos: 1
});
 
I tried to combine both FolderScripts, but I can´t get in run all opened Files saving AND closing.
Thank you very much for your help and have all a nice Weekend
kind regards
Gebhard
  

My Product Information:
Acrobat Pro 8.2.6, Windows
Gebhard
Registered: Jul 18 2011
Posts: 25
Dear WebAdministrator,
thank you for deleting the "Spam" :-)
kind regards
Gebhard
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
I believe you may be mixing things up. You've said you want to "Save" all the open PDFs, but the code looks like it is trying to extract pages from the current document? BTW: there are several errors in the code.

For the solution below I'll assume you mean to save the files, not extract pages.

var ProcessDocument1c = app.trustedFunction(function()
{
app.beginPriv();
for(var i=app.activeDocs.length-1; i>=0; i--)
{
// Get a document object off the list of Active Docs
var oDoc = app.activeDocs[i];

// Save Document back to itself
oDoc.saveAs(oDoc.path);

// Close Document
oDoc.closeDoc(true);
}
});

There are many variations on this operation. Please list exactly those actions that are required.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Gebhard
Registered: Jul 18 2011
Posts: 25
Hello Thom,
thank you for your response:-)
First, be sorry that was my mistake with the code for splitting the pages, perhaps I want to make to much as the same time.
Your code is EXACTLY what I want to do it runs perfecty!
Thank you very much and this day i enjoy my new mebership in www.scripting.com:-)
kind regards
Gebhard