How to Replace Tabs in PDF Bookmarks with JavaScript
Question details
The user needs to remove or replace tab characters in PDF bookmark names because they cause file splitting processes to fail.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Splitting a PDF document based on top-level bookmarks.
- Observed behavior
- The splitting process fails due to invalid tab characters in the bookmark names preventing the creation of new files.
Ensure you have a backup of your original PDF document before running any scripts, as automated renaming processes cannot be easily undone.
Run Document-Level JavaScript in Acrobat
Use a simple JavaScript loop in Adobe Acrobat to automatically scan and replace tab characters in all top-level bookmarks.
Tab characters are invalid in operating system file names. When splitting a PDF by bookmarks, the system attempts to use the bookmark name as the filename. If a tab is present, file creation is blocked. Running a script automates the cleanup without removing necessary punctuation like periods.
Launch Adobe Acrobat and open the PDF file containing the problematic bookmarks.
Navigate to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.
Type a name for your script in the Script Name field and click 'Add'.
Delete the default code in the editor and paste the following script: for (var i = 0; i < this.bookmarkRoot.children.length; i++) { var bkm = this.bookmarkRoot.children[i]; bkm.name = bkm.name.replace(/\t/g, ' '); }. Click 'OK' and close the dialog to execute the script.
Save your document to apply the changes to the bookmark names, then attempt to split the PDF again.

Manage and Split PDFs Effortlessly with WPS Office
WPS Office provides intuitive, user-friendly PDF tools that allow you to easily edit bookmarks, organize pages, and split PDF documents without needing to write or execute complex JavaScript code.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF file.
- 2. Manage Bookmarks Visually: Open the Bookmarks pane on the left sidebar. Right-click any bookmark to manually rename it and remove invalid characters easily.
- 3. Access the Split Tool: Navigate to the 'Page' tab on the top ribbon and select 'Split PDF'.
- 4. Configure and Split: Choose your preferred splitting method, select an output folder, and click 'Split' to export your separated PDF files instantly.

Frequently Asked Questions
Why does splitting a PDF by bookmarks fail?
Splitting a PDF by bookmarks often uses the bookmark name as the new file's name. If the bookmark contains invalid filename characters like tabs, slashes, or colons, the operating system will reject the file creation.
Can I rename PDF bookmarks manually instead of using JavaScript?
Yes, you can manually right-click each bookmark in the navigation pane and select 'Rename' to remove tabs or invalid characters. However, using JavaScript is much faster if you have dozens or hundreds of bookmarks.
How do I rename nested bookmarks using JavaScript?
The basic loop only processes top-level bookmarks. To rename nested (child) bookmarks, you need to write a recursive JavaScript function that iterates through the children of each bookmark node.
Are periods allowed in PDF bookmark names when splitting?
Yes, periods are generally valid characters in file names. You do not need to remove them for the splitting process to work successfully.




