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

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

New Here ,
Aug 22, 2024 Aug 22, 2024

Copy link to clipboard

Copied

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

Views

199

Translate

Translate

Report

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

correct answers 1 Correct answer

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,""); 
}

Votes

Translate

Translate
Community Expert ,
Aug 22, 2024 Aug 22, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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,""); 
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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).

Votes

Translate

Translate

Report

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