Skip to main content
helenr5250251
Participant
January 25, 2017
Question

Create one bookmark, named with filename, on page 1 of PDF

  • January 25, 2017
  • 2 replies
  • 992 views

I thought I'd cracked it with this: bookmarkRoot.createChild({cName: this.documentFileName, cExpr: "this.pageNum++", nIndex: 0});

However, it inserts the bookmark at page 2. I've done some reading and found out why this happens - createChild makes a bookmark on the page after the hidden root bookmark.

Is it possible to achieve?

NB: after running this script on a large number of PDFs my plan is to combine them into one document, then use another script to create a contents list.

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
January 25, 2017

What are you trying to achieve with your bookmark? The code you posted creates a bookmark with an action that jumps to the next page. Is that what you want? Is that maybe the reason you think that it's adding the bookmark to the second page because when you are on the first page of your document and you click on it, it jumps to page two?

If you want the bookmark to always go to the first page, try this instead:

bookmarkRoot.createChild({cName: this.documentFileName, cExpr: "this.pageNum=0;", nIndex: 0});

helenr5250251
Participant
January 25, 2017

That solves one problem, thank you for pointing out the error. Clicking the bookmark now takes me to the first page as intended. Unfortunately when my new workflow combines the PDFs, every bookmark then points to the first page of the combined document.

Bernd Alheit
Community Expert
Community Expert
January 25, 2017

When you add a document at the end of a document with 5 pages you must use this.pageNum=5;

Bernd Alheit
Community Expert
Community Expert
January 25, 2017

Bookmarks are part of the document, not pages.

helenr5250251
Participant
January 25, 2017

I see. We used PDF workflow software that does exactly what I need - it combines PDFs, and creates a new set of bookmarks, named after each section, that point to the correct page view.

Unfortunately that software is very old and has been replaced, and the new software doesn't have this functionality.

I was hoping to get around it with a script but it sounds like it's not possible.