I am trying to combine a bunch of excel files into one pdf for a report that I do every month. I can use the Combine Files button in Acrobat Pro 8 and select all the files I want, but I have to rearrange them (there are over 100 excel files) every month.
I have tried to do it with javascript, but without much luck. First, i tried using:
doc = app.openDoc({ cPath: "C:/temp/myNewDoc.pdf" })
// List of files of different extensions
aFiles = new Array( "207 P&L.xls", "251.xls", "280 P&L.xls", "294 P&L.xls");
for ( var i=0; i < aFiles.length; i++) {
// Open and convert the document
newDoc = app.openDoc({
oDoc: doc,
cPath: aFiles[i],
bUseConv: true
})
// Save the new PDF file to a temp folder
newDoc.saveAs({ cPath: "C:/temp/temp.pdf" });
// Close it without notice
newDoc.closeDoc(true);
// Now insert that PDF file just saved to the end of the first document
doc.insertPages ({
nPage: doc.numPages-1,
cPath: "C:/temp/temp.pdf",
nStart: 0
});
}
And that combined them, but didn't include any bookmarks (which I need to use the Table of Contents plug-in that I have. If there is a better way to build a dynamic TOC that can be printed, I'd be open to that). So I converted all the excel files to pdf and then tried using the insertPages method. That combined all the pdfs and kept all the child bookmarks, but the parent bookmarks that were created from each file name, don't do anything and they include the file extention. So when I run the TOC plug-in, it doesn't include those bookmarks.
When you combine files using the Combine Files button on the toolbar, it creates bookmarks for each file name, but it actually takes you somewhere (it takes you to the exact same place as the first child bookmark underneath it)when you click on it, and the bookmark name doesn't include the file extention. Is there any way to do this with javascript?
Thanks for your help,
John
First, you can create the bookmark structure you want though the bookmark object in Acrobat JavaScript. Of course you'll also have to provide a JS action for each. But since you have previous knowledge of the documents you're appending you already have all the info you need to build the bookmarks the way you want.
Another way to build more bookmarks is to use the undocumented "NewBookmark" menu item. This places a bookmark whose destination is the current page, onto the end of the bookmark list. You have to write code to then move this bookmark to the correct location and name it. But because it uses a "destination" for the action it's more robust that the JavaScript action.
You can also use JavaScript to build a primitive TOC from the bookmarks by using the "Report" object. It's not a pretty or better TOC than the plug-in will do. But since you're writing the code yourself you have more control over it. Here's an article on how to use the Report object.
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/building_reports/
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script