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

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

New Here ,
Aug 22, 2024 Aug 22, 2024

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!

TOPICS
Edit and convert PDFs , How to , PDF
660
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 22, 2024 Aug 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,""); 
}

View solution in original post

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 ,
Aug 22, 2024 Aug 22, 2024

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

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
New Here ,
Aug 22, 2024 Aug 22, 2024

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

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 ,
Aug 22, 2024 Aug 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,""); 
}
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
New Here ,
Aug 23, 2024 Aug 23, 2024

Thanks!! That's exactly what I was asking for, and I got to learn a bit about using JS/Regex on Acrobat.

 

However, there's something really odd happening, although I think this has no relation to the renaming proccess...

The "full file" has 90mb. When I split the pdf based on the bookmarks, Acrobat is creating files with 80mb, although all of them actually have only 2 or 3 pages... Do you have any idea about what could be happening?

 

Anyway, at least I successfully renamed the bookmarks, so once again, thanks!

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
New Here ,
Aug 23, 2024 Aug 23, 2024
LATEST

P.S.: All the pages are A4, and the first page of each boomark have 1 really tiny image that doesn't take 0.5% of the page. The rest is all text. I'm positive each file should have no more than 500kb (since, when I export an individual part of the report, it always generates a file with ~150kb).

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