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

Automating Bookmark Creation

jgravois
Registered: Feb 5 2010
Posts: 16

I have searched and searched for this one and I am frustrated.

I am running a batch script to add 38 .pdf documents to a report cover and now I need to also create bookmarks for each inserted document (some are 1 page and some are 2 pages and this can change daily depending on the original report being generated) using a specified (but Dynamic) labeling system.

The good news is that the reports and labels are the same and outputted to the same .pdf automatically each night.

An example would be that a spending report for property #84 needs to be inserted and a bookmark created to that page that reads 84: Monticello Manor.

I have tried an array of labels and even a XML file of labels but I can't seem to:
1. get the current page from Acrobat
2. create a bookmark that actually DOES something

I am using the following code but it is obviously incorrect.

root.createChild("84: Monticello", this.pageNum);

Thanks in advance for your assistance!!!!

My Product Information:
Acrobat Pro 9.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Instead of root use this.bookmarkRoot

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

jgravois
Registered: Feb 5 2010
Posts: 16
Thanks for that.

It now creates the bookmark but the bookmark STILL doesn't DO ANYTHING. It doesn't navigate to the page.

We are making progress ... let's keep on!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, you need to put the script in quotes.
But more importantly, your script doesn't make sense. It doesn't do anything... What is it that you want to happen when the bookmark is clicked?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

jgravois
Registered: Feb 5 2010
Posts: 16
My plan is to put the "Execute JavaScript" Batch Sequence after each insert page sequence and create a bookmark that when clicked will move the user to the correct page. As it is now, the bookmarks are being created (thanks to your correction) but when clicked, nothing happens.

I know that this is probably the dumbest way to attack this solution but I am the web developer here trying to help the account analyst and I have NEVER scripted in Acrobat before today.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The "File > Combine Files" feature will add bookmarks to the PDF. I know this isn't as Automated as a batch process because you have to select the files, but if all the files are in the same folder then this could be just as fast as a batch, and since it adds bookmarks it's a lot easier.Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jgravois
Registered: Feb 5 2010
Posts: 16
Thanks for the reply.

The Combine Files feature was actually the first option that I showed him (since it is FAST and EASY) but it wasn't acceptable because Oracle names the files sequentially and with the same wording (i.e., 03_snapshot.pdf, 04_snapshot.pdf) and the Board of Directors wants the bookmark to read the property code and name (i.e., 84: Monticello, 91: Rockefeller Center).
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well then you'll need to write a custom automation script. There are two approaches to adding bookmarks, you've already seen the first, using the "createChild()" function. But you can also use the "newBookmark" menu item, which will automatically set the destination to the current page. However scripting with this function is a bit trickier.

What's the script you are using right now?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jgravois
Registered: Feb 5 2010
Posts: 16
I place the script below in a batch step "Action JavaScript" directly after each batch step of "Insert Page." So, after the first insert page, my script is

this.bookmarkRoot.createChild("10: Congressional Archives", this.pageNum);
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, In a batch process the documents are not open in the viewer. So they don't have any viewing properties, such as a page number. So you just have this one line of code?

What exactly do you want this line of code to do? In the batch script "this" refers to the PDF the Batch Sequence is operating on. And the 3rd argument of createChild is the index where the new bookmark will be placed. Why are you inserting a bookmark into the current file? Don't you want the bookmark to be placed in the report file this PDF will be inserted into?

Perhaps you should explain how the insert process is supposed to work. And is it working as intended?

Adding the bookmarks and setting the destination is entirely possible. But how it's done depends on how the insertion is done.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jgravois
Registered: Feb 5 2010
Posts: 16
Thomp,

you are obviously the expert and I am not. let me reiterate what I am trying to accomplish and I will follow YOUR suggestions to make this work.

There is a GL Analyst who runs 64 reports each night from the J.D. Edwards accounting package -- one for each property the company owns and/or manages -- that are saved as separate pdf files in a specific folder on a shared drive.

Each morning he has to combine these files into a single pdf in property order and add bookmarks to each page and then email this to all of the administrators. For what -- I don't know that.

I am the web developer at the company so I am familiar with JavaScript but I have never done anything with an Acrobat file other that create them. Since this is taking SO MUCH time for this guy each day and is so repetitive, I suggested in a staff meeting that we automate the process.

Since I opened my big mouth, I got that assignment. I read what I could read online about Acrobat and learned about the combining files feature, tried it and was denied. I then learned about the batch sequence thing, and am in the process of trying to get this to work.

I have NO IDEA if this is the right approach and look forward to ANY help you can profer.

Thanks again,
Jon
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Actually, all I wanted to know is whether or not you were successful at combining the files with the batch sequence? And exactly how it's being done. Without this information I can't make any suggestions about bookmark creation.

But it's also good to have a high level view of the process. Believe me I understand about getting stuck with a job because you suggested it;)

Yes this whole thing can be automated to a very simple process for the user. There are many different approaches. But all of them would make the process much faster, consistent, and easier to use. In fact, automating processes in Acrobat is one of the main things I'm hired to do.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jgravois
Registered: Feb 5 2010
Posts: 16
Then, to REALLY answer your question ...

I created a single page pdf that serves as the report cover. I have a sequence file that is nothing more than 64 steps using "Insert Page" and pointed to each file in order.

And yes, it works exactly as planned.

To that I have inserted a "Run Javascript" sequence step with the code mentioned in an earlier post for the bookmarks, but I have yet to get them to work. So, right now, the sequence in ONLY the "Insert Pages" steps.

Thanks again!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, now I see:) Document order is very important.

At each stage (after the insertion) the docment has a new number of pages. At the very beginning of the sequence you could have a script that sets a variable to the last number of pages and the bookmark initial bookmark index. Initially this is the number of pages in the report header.

global.nLastNumPages = this.numPages;
global.nBkIdx = 0;

Then a script between each insert would create a new bookmark and use the last page number to set the bookmark Action;

var oBk = this.bookmarkRoot.createChild(..., global.nBkIdx );
oBk.setAction("this.pageNum = " + global.nLastNumPages + ";");
global.nLastNumPages = this.numPages;
global.nBkIdx++

However this process is tedius and difficult to maintain. I would suggest another approach. Write an automation script that does the whole thing. You alread know the file names, bookmark labels, and the location of the files. So you could create JavaScript object to hold this information. All the info would be in one place so it'd be easy examine and edit at a later time. The script would also be in one place instead of scattered across 65 batch sequence entries. It could also be activated and run with a single button click. And if you wanted to generalize the process even move you could place the file data in a spreadsheet or XML file instead of hard coding it into the automation script.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

jgravois
Registered: Feb 5 2010
Posts: 16
Hi again.

This is working GREAT! I do have one problem, hence, this question:

Some of the files I am inserting run to 2 or more pages due to purchasing/spending activity. I don't think the script you suggested looks at the file to be inserted for its numPages. Therefore, on my test, I am getting some misnumbering of pages.

How would I test an insert file for multiple pages and where would I put that code. By the way, I am using the script between each insert because I couldn't figure out how to get the pdf to access an external js file.

Thanks.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Actually the script does take the inserted page count into consideration. Before each insert it saves the number of pages in the report document. After insertion of a single file, the next script uses the previous number of pages to link to the first page of the inserted pages. Then updates the new total number of pages, which should include the pages for the inserted file, for use in the next script down the line.

I haven't tested any of this so it's entirely possible that I've missed some detail. You'll need to debug the process for your own setup. The Console Window will be a great help for debug, see the links in my signature block below.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[

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