Skip to main content
Participating Frequently
October 11, 2023
Question

Bookmark using Javascripts

  • October 11, 2023
  • 2 replies
  • 1303 views

Hi

I created a java script to bookmark every page as per below. It works fine but when I then try to split the file by bookmarks level using PDF SPLIT AND MERGE ENHANCED software, then it doesn't work. If I create the bookmarks by adding them manually, then the PDF SPLIT AND MERGE enhanced software works fine. Any ideas why my bookmarks created by the script are different to the ones created manually. Here is the script I have created from a sample I found on the web.

if (app.viewerVersion < 10) {
app.addMenuItem({ cName: "Create bookmarks for every page", cUser: "Create bookmarks for every page", cParent: "Tools", 
cExec: "Createbookmarksforeverypage(this)", cEnable: "event.rc = (event.target != null);"}); 
} else {
app.addToolButton({ cName: "Create bookmarks for every page", cLabel: "Create bookmarks for every page", cTooltext: "Create bookmarks for every page", 
cExec: "Createbookmarksforeverypage(this)", cEnable: "event.rc = (event.target != null);"}); 
}
/* Create bookmarks for every page in the document */
// Double slash at front of line is a comment
function Createbookmarksforeverypage(doc) {
var root = this.bookmarkRoot;
j = 0;
try {
    for (var i = 0; i < this.numPages; i += 1)
       {
if (i == 0) {
       root.createChild((i+1), "this.pageNum=" + i, i);
       j = 1;
} else {
       root.createChild((j+1), "this.pageNum=" + i, i);
       j = j + 1;
}
       }
catch(e)
{
app.alert("Processing error: "+e)
}
}
This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
October 11, 2023

The plugin most likely checks the action associated with the bookmark directly. If it's a "go to a page"-type action, it uses the page number that its pointing to for the split. Since you've created a different type of action (the only kind that can be created using a script), it doesn't recognize it.

The possible solutions are:

- Create your own split file script, based on the bookmarks, which executes them and then examines the current page number in order to know where to split the file.

- Convert the actions created by your script to "go to a page"-type actions.

 

I've developed (paid-for) tools for either option, if you're interested:

- https://www.try67.com/tool/acrobat-extract-chapters-by-bookmarks

- https://www.try67.com/tool/convert-javascript-links-to-real-links

 

Participating Frequently
October 11, 2023

Thank you TRY67. I will look into your paid for software and try it out.

Bernd Alheit
Community Expert
Community Expert
October 11, 2023

When you add the bookmarks manually does you use also Javascript?

Participating Frequently
October 11, 2023

No, I dont use java script. I just click on add bookmark icon from the bookmarks side panel and type in the bookmark name.

Thom Parker
Community Expert
Community Expert
October 11, 2023

Bookmarks created with a script cannot be used to split a document. 

 

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