How to Add JavaScript and Customize Hyperlinks in PDF Files
Question details
The user wants to know how to create advanced PDF hyperlinks, such as adding JavaScript actions, customizing internal page links, and why standard HTML class selectors cannot be used in PDF web links.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating advanced navigational links or executing complex HTTP requests within a PDF document.
- Observed behavior
- Standard web links in PDFs execute simple URLs and do not support HTML class attributes. Users need to rely on link properties, named destinations, or JavaScript for advanced hyperlink behaviors.
Ensure you have a professional PDF editor installed and access to the document's editing permissions before attempting to modify link properties or add JavaScript.
Create Internal Page Links and Named Destinations
Use this method to help users navigate to specific pages or views within the same PDF document.
Standard web link tools are primarily designed for external URIs. To navigate inside the document, you need to use the specific document link tools that allow targeting page views or named destinations.
Open the Edit PDF tool in your PDF editor and click on the 'Link' option.
Select 'Add/Edit Web or Document Link' from the drop-down menu to open the Create Link dialog box.
Choose 'Go to a page view' as your link action and click 'Next'.
Draw a box where you want the link positioned, navigate to the target page and desired zoom level, and click 'Set Link'.

Add JavaScript Actions to PDF Hyperlinks
Ideal for executing complex HTTP requests or custom behaviors that standard URL web links cannot handle.
Convert HTML to PDF to Retain Named Destinations
Use this approach if you have an existing HTML document with named destinations that you want to preserve as PDF links.
Easily Manage PDF Hyperlinks with WPS Office
WPS Office provides an intuitive PDF editor that allows you to seamlessly add, edit, and format hyperlinks. Whether you are linking to external websites or creating internal document navigation, WPS Office makes it straightforward and efficient.
- 1. Open your PDF document: Launch WPS Office and open the PDF document you want to edit.
- 2. Access the Edit tools: Navigate to the 'Edit' tab located on the top ribbon.
- 3. Add a new link: Click on the 'Link' tool and choose either 'Add Web Link' or 'Add Document Link' depending on your needs.
- 4. Configure the link destination: Draw the link area on your page and type in the target URL or configure the page destination in the prompt window.

Frequently Asked Questions
Why can't I use HTML class tags like <a class="..."> in PDF web links?
PDF web-link annotations are designed to support standard URLs, not editable HTML code. The PDF structure does not process HTML DOM properties like class selectors. For advanced styling or behavior, you must configure the link properties directly using a PDF editing tool.
Can a PDF hyperlink execute a complex HTTP request?
Standard PDF web links are limited to executing simple URL requests. If you need to execute a more complex HTTP request, you must assign a 'Run a JavaScript' action to the link instead of using the default 'Open a web link' action.
Why do my PDF links fail to handle special characters in URI actions?
Some default Web Link tools fail to properly encode or decode UTF-8 characters when handling special or reserved characters in URI actions. To avoid this issue, do not use standard web link tools to generate these URI actions; instead, use a JavaScript solution.




