How to Highlight PDF Text Automatically When Clicking a Bookmark
Question details
The user wants to configure a PDF bookmark so that clicking it not only navigates to the target page but also dynamically highlights a specific paragraph or sentence.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating interactive PDF documents where navigating via bookmarks automatically draws the reader's attention to specific content using highlights.
- Observed behavior
- By default, PDF bookmarks only navigate to a specific page or view. They do not highlight or select the specific text the user intends to emphasize upon arrival.
Ensure you are using a professional PDF editor that supports running JavaScript actions from bookmarks, such as Adobe Acrobat Pro, as standard PDF readers may not execute bookmark scripts.
Use JavaScript Actions on Bookmarks to Create Highlight Annotations
Add a custom JavaScript action to your bookmark properties that triggers a highlight annotation over a specific location upon clicking.
You can program a bookmark to execute Acrobat JavaScript. This script can be set up to dynamically create a highlight annotation at specific page coordinates or toggle the visibility of an existing annotation when the bookmark is clicked.
Since this method relies on exact page coordinates, any changes to the document's layout later on might misalign the highlight.
Open the PDF editor, navigate to the desired page, and create a new bookmark in the Bookmarks panel on the left.
Right-click the newly created bookmark and select 'Properties' from the context menu.
Go to the 'Actions' tab. From the 'Select Action' dropdown menu, choose 'Run a JavaScript' and click the 'Add' button.
In the JavaScript Editor window, input the code to add a highlight annotation using the addAnnot method. You will need to specify the page number and precise 'rect' coordinates for your text.
Click 'OK' to save the script. Close the properties dialog and click the bookmark to verify that the highlight appears over the correct text.

Highlight and Bookmark PDFs Easily with WPS Office
While scripting custom bookmark highlights can be overly complex and prone to coordinate errors, WPS PDF provides intuitive tools to instantly highlight important text and associate them with organized bookmarks. Annotate, edit, and manage PDFs without writing a single line of code.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the target PDF file using the WPS PDF viewing tab.
- 2. Highlight the text manually: Select the 'Comment' tab, click the 'Highlight' tool, and drag your cursor over the sentence or paragraph you want to emphasize.
- 3. Add a bookmark to the highlighted section: Navigate to the highlighted page, open the Bookmarks pane on the left sidebar, and click the '+' icon to create a new bookmark pointing directly to this page.

Frequently Asked Questions
Can standard PDF readers execute dynamic bookmark highlights?
Most basic PDF readers cannot execute JavaScript actions attached to bookmarks. To ensure the highlight script runs properly, users typically need to open the document in a fully-featured PDF editor like Adobe Acrobat.
Will the highlight remain accurate if I add new pages to the PDF?
If you use JavaScript to specify page coordinates, adding or rearranging pages may misalign the highlight or place it on the wrong page entirely. You will need to update the script's page parameters if the document layout changes.
Is there an easier way to highlight text on bookmark click without coding?
Without using JavaScript, the standard and most reliable approach is to manually apply a highlight annotation to the text in the document beforehand, and then set a standard bookmark to navigate directly to that specific page or zoomed view.




