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

List all bookmarks problem

bdryburgh
Registered: Oct 12 2006
Posts: 15
Answered

I am currently using Adobe Acrobat 9.0 Professional. I have a large 1400+ page scanned document with several bookmarks in it. I need to create a listing of the bookmarks. I'm using the standard list all bookmarks sequence which I've copied here for reference:

/* List all Bookmarks */
/* Recursively work through bookmark tree */
function PrintBookmarks(bm, nLevel) {
 
if (nLevel != 0) { // don't print the root
bmReport.absIndent=bmTab*(nLevel-1);
bmReport.writeText(util.printf("%s",bm.name));
}
 
if (bm.children != null)
for (var i = 0; i < bm.children.length; i++) PrintBookmarks(bm.children[i], nLevel + 1); }
// Set up the parameters to write a report
bmTab = 20;
bmReport = new Report();
bmReport.size = 2 // Large font size for title
bmReport.writeText(this.title);
bmReport.writeText(" "); // Skip a line
bmReport.size = 1.5; // Slightly smaller for heading
bmReport.writeText("Listing of Bookmarks");
bmReport.writeText(" ");
bmReport.size = 1; // Default size for everything else
PrintBookmarks(this.bookmarkRoot, 0); // Start moving through bookmarks
// Make it global so the object will be "remembered" after batch is done.
global.bmRep = bmReport;
// Make global for next step
reportDoc = global.bmRep.open("Listing of Bookmarks");
console.println("Executed Report.open");
reportDoc.info.title = "Bookmark Listings";
reportDoc.info.Author = "A. C. Robat";

The problem I'm having is that the bookmarking code is only producing the first page of bookmarks and then stops. It gets to the end of the first page and then just stops. Is there some change to the code I can make to force it to move on and print the rest of the bookmarks?

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The problem is that there is a bug in the "Report" object in Acrobat 9. This is a venerable old object that has worked flawlessly for many versions. I don't know what they did in 9, but it screwed things up.

Specifically, the problem is that it will not create a new page when the old page overflows. You have to manually call the "report.pageBreak()" function. Of coures, from the script there is no direct way of knowing when the page overflows, so you have to guess.

To do this, add a counter to the loop. Make it a global variable, i.e. declare it outside the "PrintBookmarks" function. Then increment it after every "bmReport.writeText()" call. At the bottom of the function add an "if" to test the number of lines printed, if its greater that the pageMax then reset the counter and call the "report.pageBreak()" function.

The question of coures is, what is "pageMax". To find out count the lines on the print out you already got for the original 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]

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

dhoang
Registered: Jun 19 2009
Posts: 1
Thanks for hints.
I am attempting to modify the batch sequence. Acrobat message: bmReport.pageBreak() is not a function. Any idea?
Chrystela
Registered: Oct 27 2009
Posts: 6
Hey, I read your message and do not understand how to execute it. Can you send me a more detailed set of instructions. I have a ton of bookmarks in a ton of documents and my boss wants a list of the bookmarks to accompany the hard copy of the document. As you may know to type that list is incredibly time consuming, so any help that you can give would be so very appreciated.

• /* List all Bookmarks */
• /* Recursively work through bookmark tree */
• function PrintBookmarks(bm, nLevel) {
• if (nLevel != 0) { // don't print the root
• bmReport.absIndent=bmTab*(nLevel-1);
• bmReport.writeText(util.printf("%s",bm.name));
• }
• if (bm.children != null)
• for (var i = 0; i < bm.children.length; i++)
• PrintBookmarks(bm.children[i], nLevel + 1);
• }
• // Set up the parameters to write a report
• bmTab = 20;
• bmReport = new Report();
• bmReport.size = 2 // Large font size for title
• bmReport.writeText(this.title);
• bmReport.writeText(" "); // Skip a line
• bmReport.size = 1.5; // Slightly smaller for heading
• bmReport.writeText("Listing of Bookmarks");
• bmReport.writeText(" ");
• bmReport.size = 1; // Default size for everything else
• PrintBookmarks(this.bookmarkRoot, 0); // Start moving through bookmarks
• // Make it global so the object will be "remembered" after batch is done.
• global.bmRep = bmReport;
• // Make global for next step
• /*
• */
• if ( app.viewerVersion < 7 ) {
• global.wrtDoc = app.setInterval(
• 'try {'
• +' reportDoc = global.bmRep.open("Listing of Bookmarks");'
• +' console.println("Executed Report.open");'
• +' app.clearInterval(global.wrtDoc);'
• +' delete global.wrtDoc;'
• +' console.println("Executed App.clearInterval");'
• +' reportDoc.info.title = "Bookmark Listings";'
• +' reportDoc.info.Author = "A. C. Robat";'
• +'} catch (e) {console.println("Waiting...: " + e);}'
• , 100); // Check every 1/10th of a second. You can adjust this
• } else {
• reportDoc = global.bmRep.open("Listing of Bookmarks");
• console.println("Executed Report.open");
• reportDoc.info.title = "Bookmark Listings";
• reportDoc.info.Author = "A. C. Robat";
• }
Chrystela
Registered: Oct 27 2009
Posts: 6
Come on Thom, what is the solution? Give it up man:). Please:).
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
bdrybrugh, Sorry I didn't answer earlier. I wasn't subscribed:( The Answer is. report.breakPage is the function. The problem still exists in Acobat 9.2


Chrystela: There are a couple of ways you could run this code. I typically create a folder level Automation script if it's something I need to do more then once. But the fastest easiest way to just try it out is to run this code from the console window. Theres detailed info on the console in my signature block.

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

bdryburgh
Registered: Oct 12 2006
Posts: 15
Oh, that one little piece changed everything for us! We never got the error message dhoang got, but it just wouldn't [i]do[/i] anything.

Chrystela, I'm putting the code for the version we got working here. Our version puts the page numbers of the bookmarks in it too, though - you might want to remove that piece.

/* List all Bookmarks *//* Recursively work through bookmark tree  */function PrintBookmarks(bm, nLevel){if (nLevel != 0) { // don't print the root bmReport.absIndent=bmTab*(nLevel-1);bm.execute();bmReport.writeText("(page# "+(bm.doc.pageNum +1)+ ") "+bm.name);lineCount += 1;if (lineCount >= pageMax) {bmReport.breakPage();lineCount = 0;}}if (bm.children != null)for (var i = 0; i < bm.children.length; i++)PrintBookmarks(bm.children[i], nLevel + 1);}lineCount = 0;pageMax = 50;bmTab = 20;bmReport = new Report();bmReport.size = 2;bmReport.writeText(this.title);bmReport.writeText(" ");bmReport.size = 1.5;bmReport.writeText("Listing of Bookmarks");bmReport.writeText(" ");bmReport.size = 1;PrintBookmarks(this.bookmarkRoot, 0);global.bmRep = bmReport;  // make globalglobal.wrtDoc = app.setInterval('try {'+'       reportDoc = global.bmRep.open("Listing of Bookmarks");'+'       console.println("Executed Report.open");'+'       app.clearInterval(global.wrtDoc);'+'       delete global.wrtDoc;'+'       console.println("Executed App.clearInterval");'+'       reportDoc.info.title = "Bookmark Listings";'+'       reportDoc.info.Author = "List Bookmark Sequence";'+'} catch (e) {console.println("Waiting...: " + e);}', 100);

And just play around with the pageMax # to get how many lines per page you need.
Chrystela
Registered: Oct 27 2009
Posts: 6
Oh my g-d. Thank you so very, very much B. You are the BEST! I have been working on this thing all day. You have saved me literally hours of time.

And thank you Thom for all of the lessons.
Sarahkeeling
Registered: Nov 25 2009
Posts: 4
Hi bdryburgh,

I am having trouble trying to get a list of bookmarks with page numbers, which it seems you have solved! However, if I copy your coding into a new batch sequence and run it, all I get is another version of my complete PDF file. I only want a list of bookmarks and page numbers - am I doing something silly??

I have absolutely NO idea how batch processing works and this is the first time I've tried to do anything with it, so apologies if I seem a little dim . . .

Thanks

Sarah
bdryburgh
Registered: Oct 12 2006
Posts: 15
Try playing around with the other options that aren't javascript. I have better luck with changing the run command on to "files open in Acrobat" and actually opening the file that needs the bookmarks.
Sarahkeeling
Registered: Nov 25 2009
Posts: 4
Thank you SO very much! I tried it again, but with the PDF open and voila!! Exactly what I needed.

You don't know how much better my day just got!

Cheers
ayusuf
Registered: Dec 21 2009
Posts: 30
Hi below is my code and I was wondering if you guys could help me out. I'm trying to format the table of contents where the Page Number prints at the line. It would be great if you guys could help me. Thanks.

/* List all Bookmarks *//* Recursively work through bookmark tree  */function PrintBookmarks(bm, nLevel){if (nLevel != 0) { // don't print the root bmReport.absIndent=bmTab*(nLevel-1);bm.execute();bmReport.writeText(bm.name + "  Page #" + (bm.doc.pageNum + 1));lineCount += 1;if (lineCount >= pageMax) {bmReport.breakPage();lineCount = 0;}}if (bm.children != null)for (var i = 0; i < bm.children.length; i++)PrintBookmarks(bm.children[i], nLevel + 1);}lineCount = 0;pageMax = 50;bmTab = 20;bmReport = new Report();bmReport.size = 2;bmReport.writeText(this.title);bmReport.writeText(" ");bmReport.size = 1.5;bmReport.writeText("Listing of Bookmarks");bmReport.writeText(" ");bmReport.size = 1;PrintBookmarks(this.bookmarkRoot, 0);global.bmRep = bmReport;  // make globalglobal.wrtDoc = app.setInterval('try {'+'       reportDoc = global.bmRep.open("Listing of Bookmarks");'+'       console.println("Executed Report.open");'+'       app.clearInterval(global.wrtDoc);'+'       delete global.wrtDoc;'+'       console.println("Executed App.clearInterval");'+'       reportDoc.info.title = "Bookmark Listings";'+'       reportDoc.info.Author = "List Bookmark Sequence";'+'} catch (e) {console.println("Waiting...: " + e);}', 100);
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
And What's not working?

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

ayusuf
Registered: Dec 21 2009
Posts: 30
It's working I'm just wondering if somebody could modify the code where the Title of the bookmark comes on the left hand side and then all the way on the right hand side comes the page number. Thanks and I hope that makes sense.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
It's not possible to ident the text of a report all the way to the right. If you try it, it will come out at the center of the page.

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

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Reports are particularly difficult in this way. They are not meant to be an all purpose page layout tool, but rather a very simple way of collecting data. If you want to do something fancier then you'll need to be clever. There are several possibilities.

For example, have you tried using tabs? You should be able to get all the page numbers lined up. If you use a fixed width font then you could use periods and spaces to separate the title from the page numbers. Be sure to accound for the indent and the number of characters in the title.

Or anther way would be to print the page numbers out on a different page entirely, then merge the title and page number pages after the report is converted to PDF. Use either page templates or watermarks to do the merge.

I'm sure there are other schemes.

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

daka630
Expert
Registered: Mar 1 2007
Posts: 1420
Brenda's fix package as a "turn-key" solution.

From Rick Borstein's blog -
List Bookmarks with a Free Script (Updated for Acrobat 9)
http://blogs.adobe.com/acrolaw/2009/12/list_bookmarks_with_a_free_scrip.php

Be well...

Be well...

ToddHendrickson
Registered: Oct 20 2010
Posts: 1
I tried bdryburgh most recent script and I got an message indicating a syntax error when trying to save the script. Anyone have a corrected script?

Todd N. Hendrickson

richarmon1
Registered: Jan 30 2011
Posts: 1
I'm trying to print the continuation of a form block that I created. How do you get the data that goes over the space alloted in a form to print?