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

Combining Files

ndarmyserver
Registered: Jan 17 2008
Posts: 2

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

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You've got a complex process here. As you've already figured out, there are a lot of different ways to go about doing it, and there are a lot of pitfalls. But you seem to have done pretty well so far:)

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

1800theeagle
Registered: Feb 5 2008
Posts: 1
Thomp,
I've notived you have mentioned that undocumented NewBookMark method in other replies.

Can you please provide a code example on how to implement this?

Thanx
David
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
"NewBookmark" is a the menu item ID for the Create new bookmark option in the Bookmark panel context menu.

When you run this menu item it does exactly what the menu item does, creates a new bookmark named "Untitled", with the focus on the bookmark in edit mode. There are some tricks to using this in code, which I can't get into right now because they deserve an artical.

Use this code to run it:

app.execMenuItem("NewBookmark");

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