Skip to main content
Participating Frequently
January 10, 2020
Question

Script to create/name bookmark from text in the pdf

  • January 10, 2020
  • 3 replies
  • 9920 views

Hello,

 

I'm wondering how I can create a script that will create a bookmark and then name it with a value in the PDF file. The value is a randomized number that will have the same number of characters. So if the pdf is ten pages, I should have ten bookmarks named with that unique number.

 

After this is done my plan is to be able to split the pdf file based on the bookmark. Unless this can be scripted too but that's for another time.

 

Thanks for any help you can provide.

This topic has been closed for replies.

3 replies

Thom Parker
Adobe Expert
January 15, 2020

So is your ultimate goal to save each page of the PDF to a file unique name? 

This is much easier to do with a script than creating bookmarks. 

Use the "doc.extractPages()" function, which you can read about here:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_extractPagesbc-33&rhtocid=_6_1_8_23_1_32

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
SummerHayah
Participating Frequently
January 15, 2020

For my situation I need to split and save the file as the unique ID text on each page

New Participant
May 6, 2020

Well, I certainly appreciate all the input and shared knowledge, but I think for me it is easier to simply add the book marks and split the pages and save according to top level book mark.

 

I was really hoping to beable to automate adding the book marks.

 

Thank You


did you get your solution? I am in a similar situation.

JR Boulay
Adobe Expert
January 11, 2020

my plan is to be able to split the pdf file based on the bookmark

This can be automated with the Action wizard or by using "Split Multiple Files".

 

Acrobate du PDF, InDesigner et Photoshopographe
SummerHayah
Participating Frequently
January 13, 2020

Hello;

 

I am looking to do the same. I have a large pdf every 2 pages is associated with a particular individual. I have ID numbers on each page that is unique to each individual, so I was looking to have a javascript to do the following:

 

1. Automatically set bookmarks to the position of the ID number and name the bookmark as the ID number

2. Split the pages  in correspondence to the unique id numer

3. Save each file separetly as the unique id number for file name

 

I have the javascript for renaming files as the unique id bookmark working, but automating creating bookmarks as the Unique ID I am struggling with

 

Any help would be appreciated

Nuge93Author
Participating Frequently
January 13, 2020

Nice work, sounds like you're further along than I. Would you be willing to provide your code for creating/naming the bookmark? This is the step I'm hung up on as my programming/scripting skills are not up to snuff.

Thom Parker
Adobe Expert
January 10, 2020

With a script there are two ways to create a bookmark. 

1) use the "bookmark.createChild()" function. This creates a bookmark with a JavaScript Action. You can read about it here:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FBookmark_methods.htm%23TOC_createChildbc-1&rhtocid=_6_1_8_8_1_0

 

You'll need to learn a bit about bookmark navigation. 

 

2) use the menu item "NewBookmark", which creates a new unnamed bookmark following the currently selected bookmark. The bookmark action is the destination of the current page view. While this method is the only way to create bookmarks with true destinations from a script, it is extremely problematic for two reasons. First, the exeMenuItem function is non-blocking, so you don't know when and if the bookmark is created. And second, this menu item is intended to be used from the user interface, so it places the keyboard focus into the currently created bookmark, making it impossible to rename that bookmark.  

 

 

Frankly, it might be much easier to just split the document. On what basis is the split.

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often