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

Trying to write a code to create bookmarked on all highlighted values in a document

New Here ,
Feb 10, 2023 Feb 10, 2023

I've gone through and highlighted a lot of values in a pdf using the "Find, Highlight, and Extract" tool, and now I'm trying to make a bookmark at each highlighted value.  I'm trying to work something out but I keep getting errors.  Any help would be greatly appreciated!

 

var valuesToFind = ["1", "2"];

for (var i = 0; i < valuesToFind.length; i++) {
  this.syncAnnotScan();
  var results = this.search(valuesToFind[i], true, true);

  for (var j = 0; j < results.length; j++) {
    var result = results[j];

    var bookmark = this.addAnnot({
      type: "Bookmark",
      page: result.page,
      rect: result.rect,
      name: valuesToFind[i]
    });
  }
}

 

TOPICS
Mac
397
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 ,
Feb 10, 2023 Feb 10, 2023
LATEST

I don't know where you've been getting your information from, but you need to look through the Acrobat JavaScript reference to find out what functions and properties are available. There's also lots of sample code in the reference.

 

For example, there is no document "search" function. Doesn't exist. Here's Doc object reference entry

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#doc

 

 

There is no such thing as a bookmark annotation. Here is the Acrobat JavaScript Reference entry for the annotation types:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#annotation-type...

 

What you want to do is create a bookmark, here's the reference entry for the bookmark object.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#bookmark

 

To seach for a particular type of annotation, use the "doc.getAnnots" function to get an array of all annotations on the PDF. The sort for the type:

 

var aAnnots = this.getAnnots();
if(aAnnots){
  var aHiLites = aAnnots.filter(a=>a.type == "Highlight");
  for(var i=0;i<aHiLites.length;i++){
     ... Add bookmark code ...
   }
}

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

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