Skip to main content
Participant
August 22, 2024
Answered

Batch rename bookmarks to remove special characters and then Split the file

  • August 22, 2024
  • 1 reply
  • 946 views

I have a PDF with about 1500 pages and 1000 bookmarks (it's an auto-generated report from a tool we use).

I tried splitting the file basing it on the bookmarks, however, all of them have special characters, which I later found out to be the reason I always receive the error "The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder" when trying to split it (just to be clear, I'm not using any cloud services, and I have full permissions to read/write in any folder in my drive).

 

Does someone know of any way to automaticaly rename all the chapters? All of them have follow this pattern:

[BCC-0000] Name ~ With_Special > Characters ~

[BCC-0001] Name ~ With_Special > Characters ~

[BCC-0003] Name ~ With_Special > Characters ~ and so on.

I believe the best approach would be keeping only the first characters of the name, removing the "[ ]" if possible, or just use regex, but I have no idea on how to achieve this.

 

Thanks!

This topic has been closed for replies.
Correct answer try67

Run this code from the JS Console:

 

for (var i=0; i<this.bookmarkRoot.children.length; i++) {
	var bkm = this.bookmarkRoot.children[i];
	bkm.name = bkm.name.replace(/[\]\[\\\/\:\*\?\"\<\>\|!\^\n\r\v\t]/g,""); 
}

1 reply

try67
Community Expert
Community Expert
August 22, 2024

Do all the bookmarks appear at the top-most level of the tree? In other words, are there any child bookmarks?

Participant
August 22, 2024

Thankfully, yes, all of them are at the top-most level.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 22, 2024

Run this code from the JS Console:

 

for (var i=0; i<this.bookmarkRoot.children.length; i++) {
	var bkm = this.bookmarkRoot.children[i];
	bkm.name = bkm.name.replace(/[\]\[\\\/\:\*\?\"\<\>\|!\^\n\r\v\t]/g,""); 
}