Copy link to clipboard
Copied
Trying to Find and Replace text within "Bookmarks Only". Using Ctrl+F, one can Find text and include Bookmarks. Once Find and Replace is selected, Include Bookmarks gets greyed out (see att.). If seen Add-ons do this in the past, but the current Acrobat doesn't have this functionality.
Copy link to clipboard
Copied
May be possible with a script.
Copy link to clipboard
Copied
May be possible with a script.
Copy link to clipboard
Copied
As mentioned, this is only possible using a script, like this (paid-for) tool I've developed:
https://www.try67.com/tool/acrobat-search-replace-text-in-bookmarks
Copy link to clipboard
Copied
I just asked Copilot to create a script for me. It worked! Here's the script it generated and instructions for adding it as an icon to your toolbar! The function will also delete text from bookmarks if you leave the Replace Text user input blank.
// Define the search and replace function
function searchAndReplaceInBookmarks() {
// Prompt the user to input the old text
var searchText = app.response({
cQuestion: "Please enter the text you want to search for:",
cTitle: "Search Text"
});
// Prompt the user to input the new text
var replaceText = app.response({
cQuestion: "Please enter the replacement text (leave blank to delete the search text):",
cTitle: "Replace Text"
});
// Get the root bookmark item
var rootBookmark = this.bookmarkRoot;
// Call the recursive function to search and replace text
searchAndReplaceInBookmarkItem(rootBookmark, searchText, replaceText);
}
// Recursive function to search and replace text in each bookmark item
function searchAndReplaceInBookmarkItem(bookmarkItem, searchText, replaceText) {
// Check if the bookmark item has children
if (bookmarkItem.children != null) {
for (var i = 0; i < bookmarkItem.children.length; i++) {
// Recursive call for each child bookmark item
searchAndReplaceInBookmarkItem(bookmarkItem.children[i], searchText, replaceText);
}
}
// Check if the bookmark item's name contains the search text
if (bookmarkItem.name.indexOf(searchText) != -1) {
// If replace text is not provided, delete the search text
if (replaceText === "") {
bookmarkItem.name = bookmarkItem.name.replace(searchText, "");
} else {
// Replace the search text with the replace text
bookmarkItem.name = bookmarkItem.name.replace(searchText, replaceText);
}
}
}
// Call the function when the document is opened
searchAndReplaceInBookmarks();
This script will now check if the replaceText is empty and if so, it will remove the searchText from the bookmark names. If replaceText is provided, it will replace the searchText as before. Remember to save your document before running the script to prevent any unintended changes. If you have any more questions or need further modifications, feel free to ask!
To add a shortcut icon to your document toolbar in Adobe Acrobat Pro for the script, you'll need to create an Action with the Action Wizard and then add this Action to the Quick Tools Toolbar. Here's how you can do it:
Now you will have a shortcut icon on your Quick Tools Toolbar that will run the script when clicked. Remember to save your document after making these changes. If you need any further assistance or clarification, please let me know!
Copy link to clipboard
Copied
Thanks, very useful.
There is however one aspect that I would need to improve.
The script launched with an action on multiple documents proposes the search/replace window for each document.
Is it possible to modify the script so that the insertion of the text to search/replace is asked only once (not once for each document) and the replacement is applied to all documents?
Copy link to clipboard
Copied
In order to do that you would need to save the user input into global variables and then change the code to use them if they exist, and if not, prompt the user to enter them. That way they will be prompted for the first file, and the ones after it will be processed automatically.