Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 25, 2017 Jan 25, 2017

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.

TOPICS
Acrobat SDK and JavaScript
897
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2017 Jan 25, 2017

Bookmarks are part of the document, not pages.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2017 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2017 Jan 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});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2017 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2017 Jan 25, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2017 Jan 25, 2017

So what I need to do is:

Add document A

  Add bookmark

  If number of pages is odd, add blank

  Calculate total pages

Add document B

  Add bookmark (total pages +1)

  If number of pages is odd, add blank

  Calculate new total pages

etc...

Sounds like this is waaaay beyond me! I'll get on to the people who provide our workflow software and see if they can help us out.

Thanks for the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2017 Jan 25, 2017
LATEST

this.numPages will you give the number of pages in the open document.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines