How to Add Web Links to PDFs Using Acrobat JavaScript
Question details
The user wants to programmatically add a functional web link to a PDF using Acrobat JavaScript, while noting that the method creates a JavaScript action instead of a standard native web link action.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Automating the creation of interactive hyperlinks within a PDF document using the Acrobat JavaScript API.
- Observed behavior
- Using setAction with getURL creates an action classified as JavaScript rather than a standard 'Open a web link' action, though it successfully routes the user to the intended URL.
Ensure you have access to the JavaScript console or scripting editor in your PDF application, and verify that the target URL is formatted correctly (e.g., including 'http://' or 'https://').
Use the app.launchURL Method with setAction
This is the most reliable way to programmatically trigger a web address to open using Acrobat JavaScript.
While the Acrobat JavaScript API cannot programmatically create a standard native 'Open a web link' action, you can achieve the exact same user experience by creating a JavaScript action that launches a URL. The underlying action remains classified as JavaScript, but it functions identically for the end user.
First, obtain the reference to the link annotation object you want to modify in your PDF script, typically referred to as 'myLink' in your code block.
Use the setAction method to assign the launch command. Input the code: myLink.setAction("app.launchURL('http://adobe.com');"); replacing the URL with your target web address.
Run the script in your JavaScript console. Click the modified link in the PDF document to ensure it properly opens the default web browser and navigates to the specified URL.

Use the this.getURL Method
An alternative scripting approach to fetch and open a web link via PDF JavaScript.
Easily Add Native Web Links Visually in WPS PDF
If you want to create standard, native PDF web links without writing complex JavaScript, WPS PDF offers an intuitive visual editor. You can quickly draw link areas and assign URLs with perfect compatibility.
- 1. Open your PDF in WPS Office: Launch WPS Office, select the 'PDF' tab, and open the document you wish to edit.
- 2. Access the Link tool: Navigate to the 'Edit' tab on the top ribbon and click on the 'Link' button.
- 3. Draw the link area: Click and drag your cursor over the text or image where you want the hyperlink to be active.
- 4. Enter the URL: In the pop-up dialog box, select 'Open a web page', type in your destination URL, and click 'OK'.

Frequently Asked Questions
Why doesn't setAction create a standard 'Open a web link' action?
The Acrobat JavaScript API is designed specifically to bind JavaScript actions to PDF elements. While a script can command the PDF viewer to open a URL, the action itself is embedded as executable code, which the PDF specification strictly classifies as a JavaScript action.
Can I programmatically create other native PDF action types with this API?
No. The JavaScript API in Acrobat is limited to generating JavaScript actions. You cannot programmatically script the creation of native URI, GoTo, or Launch action types using this specific setAction method.
Will links created with app.launchURL work on mobile PDF viewers?
Support depends entirely on the mobile PDF viewer. While standard native links work universally, JavaScript actions are often disabled or unsupported in basic mobile PDF apps. For maximum compatibility across all devices, native visual links are recommended.




