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

exporting bookmarks with page numbers

ArielZusya
Registered: Jan 11 2009
Posts: 6
Answered

I've got a 9000+ page pdf files that contains thousands of scanned documents. The person who put the file together bookmarked the first page of each document but created no other TOC or other reference. I've been asked to figure out a way to generate a TOC from the bookmarks. I've figured out how to export the bookmarks (using a batch sequence file) but I haven't yet been successful figuring out how to export the page numbers with it. I'm not a programmer and I don't begin to pretend to know how to code in javascript (so don't laugh too much at the following). I was hoping to modify the "List All Bookmarks" sequence (which i believe came with Acrobat 7) which looked like this:

/* 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);                           
}
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 global
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 = "List Bookmark Sequence";'
    +'} catch (e) {console.println("Waiting...: " + e);}'
    , 100);

To something like this:

/* 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));
        bmReport.writeText(util.printf("%s", bm.action.page));
    }        
    if (bm.children != null)
          for (var i = 0; i < bm.children.length; i++) 
            PrintBookmarks(bm.children[i], nLevel + 1);                           
}
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 global
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 = "List Bookmark Sequence";'
    +'} catch (e) {console.println("Waiting...: " + e);}'
    , 100);

Unfortunately (and probably obviously to anyone who actually knows javascript coding) I can't simply add:

bmReport.writeText(util.printf("%s", bm.action.page));
Can someone give me a hand with what I would need to add or change in the "List All Bookmarks" batch sequence to have it export the page number of the bookmark as well? Thanks for your help!

My Product Information:
Acrobat Pro 8.0, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi ArielZusya,

Not sure where you got the action.page but there is no "action" property in Acrobat JS. While I am not a "real" programmer, I do play one on the internet-LOL. I tried my hand at fixing the script below (with a little help from my JS guru partner)- try it out and see if it will work for you. It was a good exercise for me and I hope it works for you.


/* 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); }if (bm.children != null)for (var i = 0; i < bm.children.length; i++)PrintBookmarks(bm.children[i], nLevel + 1);}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);

Hope this helps,

Dimitri
WindJack Solutions
www.windjack.com
www.pdfscripting.com
ArielZusya
Registered: Jan 11 2009
Posts: 6
Brilliant! Thank you so much for your help. I should have come here first. I posted the same question on the Acrobat Javascript forum at Adobe.com and got completly useless responses. Thanks so much!
Cat
Registered: Feb 3 2008
Posts: 1
Hello. Could someone assist me please. I am trying to do the same thing in Acrobat 8 - have the bookmarks show with the corresponding page number and then would like to be able to print the list. I see the script at the very end of this thread but I am inexperienced and have no idea on how to use the script. I do not know code or javascript but was hoping there might be a work around. I am working on the agenda and while I have the page numbers showing in a footer and have the bookmarks listed on the side, I would like to see the bookmarks with the page numbers as well.

Can someone direct me please.

Thank you.

Cat
jaymade
Registered: Nov 5 2009
Posts: 1
this might be a dumb question, but where are you pasting the java script posted above?

I normally have InDesign create the bookmarks links with page numbers based upon the content of catalog. Product revision control forced us to have individual pdfs for each product then booklet together in chapter form forcing me to loose table of content automation. I have the bookmarks for product description as well as part numbers that needs to be indexed.

The work is already completed in PDF format but would like to export the bookmarks with page numbers to a separate file.

I ran the "list all bookmarks" sequence and have a seperate file containing the information needed except the page number.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Acrobat Professional has a JavaScript debugging console where one could cut and paste the code. But if I expected to use this code frequently, I would use an application level folder for the file and add a button or menu item.

George Kaiser

lawvol
Registered: Dec 3 2009
Posts: 8
Dimitri:

I tried running your version of the script, and got the following is response:

nLevel is not defined2:Console:ExecnLevel is not defined2:Console:Execundefined

I'll be the first to admit that I am completely new to javascript, what does that mean? I searched for "nLevel" but couldn't seem to find anything that helps me.

Thanks for any help you can offer.

===================================

Okay I figured out the problem above -- wasn't selecting the full code when running. Now, however, I am getting the following message

[code][object TimeOut][/code]
Any thoughts?

============
Lawvol

40grit
Registered: Mar 26 2010
Posts: 1
I have typed the above code (or something similar) and it works properly.... sometimes.

On one file it works just perfectly and the output is as expected.

On another file, it puts a carriage return in the line.

The files upon which the script works properly are all (so far) downloaded from adobe (reference manuals and the like).

The files where the script misbehaves all (so far) seem to be created by me (printouts from excel, assembling of scanned documents and the like).

What attribute of a pdf file would be causing this difference of behavior and how would I configure my version of Acrobat Professional (8.x) to correct this so that this script when run against my files will produce the output without the spare line feed?

I could supply samples if necessary (and I knew how).

Thanks

No signature

try67
Expert
Registered: Oct 30 2008
Posts: 2398
This behavior is probably caused when you press Enter after editing the name of a bookmark. This adds a carriage return (which is not visible, or looks like a space), and then exits the edit mode. It's a bug in Acrobat (one of many, I'm afraid...).
I don't know which of the codes mentioned above you use, but they can probably be adjusted to remove any such extra line breaks using JavaScript's replace method. If you post the code, I could help you out with this.

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

13eaver
Registered: Jul 20 2010
Posts: 1
Hi,

I am trying to use this code in Acrobat 8, but nothing happens when I run the sequence. I already have a sequence called "List all bookmarks" and this works fine. Now I want to create a page with a List of all the bookmarks WITH corresponding page numbers (as close to a table of contents as I can get with Acrobat). I created a new sequence using this code (below), but when I run it and use a pdf file that has bookmarks, nothing happens. I am a complete novice regarding javascript and acrobat. What am I doing wrong?

Thank you for your help!

Dimitri wrote:
/* 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); }if (bm.children != null)for (var i = 0; i < bm.children.length; i++)PrintBookmarks(bm.children[i], nLevel + 1);}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);

Hope this helps,

Dimitri
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Acrobat JavaScirpt can not access most actions within a PDF. Although you could executing the bookmark and then use the 'pageNum' property to pick up the page the bookmark went to. But Be careful, because bookmarks can do a lot of things besides going to a given page. See the Acrobat JS API Reference for more information.

George Kaiser