How to Find and Highlight Hyperlinks in a PDF Using JavaScript
Question details
The user wants to identify and highlight visible URLs and embedded hyperlinks in lengthy PDF applications to verify compliance with NIH guidelines.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Reviewing long PDF submissions to locate all page numbers, link locations, and verify that embedded links meet specific institutional guidelines.
- Observed behavior
- The user needs to reliably detect all links, but standard JavaScript may only create JS-based link actions rather than standard web-page links, requiring external validation.
Before using JavaScript to process links in your PDF, verify with the receiving institution (like the NIH) that JavaScript-generated links or annotations meet their strict submission guidelines.
Inspect PDF Annotations with JavaScript
Use PDF JavaScript to loop through document annotations and identify existing link locations.
JavaScript can inspect PDF annotations and text to locate visible URLs and embedded links.
However, be aware that JavaScript can only create actions that execute JavaScript code natively. It cannot automatically create standard open-web-page actions for newly detected text URLs without third-party conversion tools.
Open your PDF editor and access the built-in JavaScript debugger or console from the advanced tools menu.
Run a script using the getAnnots() method to loop through all annotations on every page of the document.
Check the properties of each annotation to see if its type is defined as a 'Link' to compile a list of embedded hyperlinks.

Use Dedicated PDF Link Inspection or Conversion Tools
Utilize specialized third-party tools to find plain-text URLs and convert them into standard real links.
Easily Check and Edit Hyperlinks with WPS PDF
WPS Office provides an intuitive PDF editor that lets you view, edit, and insert standard web hyperlinks effortlessly. You can ensure all your links are compliant and functional without relying on complex JavaScript workarounds.
- 1. Open Your Document: Launch WPS Office and open your PDF document.
- 2. Enter Edit Mode: Navigate to the 'Edit' tab on the top ribbon and select the 'Link' tool.
- 3. Inspect and Modify Links: Click on any existing hyperlink area in the document to view or modify its destination URL, ensuring it meets submission requirements.
- 4. Save the PDF: Save the document to preserve the standard web-link actions securely.

Frequently Asked Questions
Can PDF JavaScript convert plain text URLs into standard web links?
No, PDF JavaScript can natively create actions that execute JavaScript code, but it cannot automatically generate a standard web-page link action. You usually need a dedicated standalone tool to convert those JavaScript links into standard real links.
Why might the NIH reject PDFs with JavaScript-generated links?
Institutions like the NIH often require standard, verifiable web links for security and accessibility reasons. JavaScript-based actions may be flagged as security risks or fail to open correctly in standard PDF readers used by compliance reviewers.
How do I find all embedded links in a lengthy PDF without scripting?
You can use a dedicated PDF editor like WPS PDF, which allows you to enter Edit mode and visually inspect or manage all link objects across the document pages without needing to write custom code.




