Skip to main content
DellCentre039134
Participating Frequently
September 21, 2018
Answered

Rename bookmarks XXX to YYY using JS

  • September 21, 2018
  • 1 reply
  • 4472 views

I have a PDF with bookmarks which all start with XXX NAME. I want to rename XXX to YYY.. I believe the solution is very simple using JS, however Im a coding noob. Can anyone provide the javascript for this 'simple' task?

This topic has been closed for replies.
Correct answer try67

Its this line (space at end included): 'Richtlijnen voor de jaarverslaggeving (middelgrote en grote rechtspersonen), '

I want to just delete it (in essence replace by "")

I tried your code on another file, which had 'normal' bookmarks

'TEST 1', "TEST 2', etc. and managed to replace it to 'HELP 1', 'HELP 2' etc.


Try it without the RegExp notation, like this:

replace("Richtlijnen voor de jaarverslaggeving (middelgrote en grote rechtspersonen),", "Something else..."); 

1 reply

try67
Community Expert
Community Expert
September 21, 2018

Does the bookmark tree contain different levels, or just a single one? Changing the names is easy, but traversing a complex bookmarks tree will require a recursive function.

DellCentre039134
Participating Frequently
September 21, 2018

Its just a single bookmark level (top level).

try67
Community Expert
Community Expert
September 21, 2018

Then it's pretty straight-forward. You can use this code to do it:

for (var i=0; i<this.bookmarkRoot.children.length; i++) {

    var bkm = this.bookmarkRoot.children;

    bkm.name = bkm.name.replace(/^XXX/, "YYY");

}