# Custom trigger to hyperlinks / link and goto that are already created in original PDF

**URL:** https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505
**Category:** Technical Support
**Created:** [February 17, 2021, 4:36am UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505 "2021-02-17T04:36:38Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![fbenavides](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@fbenavides](https://pdfjs.community/u/fbenavides)
#### Post date: [February 17, 2021, 4:36am UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/1 "2021-02-17T04:36:38Z")

</div>

**PDF.js Express Version**

**Detailed description of issue**  
Hi, I am trying to display PDF documents that have external hyperlinks to files. First I need how to Active those links to work.  
Second, I need somehow to catch the event when the user click the external hyperlink and try to redirect it to existing file in the server.

I try this link for PDFTRON but it don’t work.  
[https://groups.google.com/g/pdfnet-webviewer/c/H0353b6vYwU](https://groups.google.com/g/pdfnet-webviewer/c/H0353b6vYwU)

**Expected behaviour**  
{Provide a screenshot or description of the expected behaviour}  
First, When the user click on the hyperlink, open a blank page with the link  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/11d8498933dfac9d60cddbb0f159fd5d376fe3ce.png)

**Does your issue happen with every document, or just one?**  
{Answer here}

**Link to document**  
{Provide a link to the document in question if possible}

**Code snippet**  
{Provide a relevant code snippet}

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [February 17, 2021, 5:27pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/2 "2021-02-17T17:27:44Z")

</div>

Hey there! Thanks for trying out PDF.js Express.

You’re super close. For external links, you’ll actually want to override the URI Action instead of GoToR.

```javascript
WebViewer(...).then(instance => {
  const uriTrigger = Actions.URI.prototype.onTriggered;
  Actions.URI.prototype.onTriggered = function(link) {
    //uriTrigger.apply(this, arguments); // uncomment this to use default functionality
    
    console.log(this.uri);
  };
})

```

With the URI you can do whatever you wish.

Let me know if theres anything else I can help with.

Thanks!  
Logan

---

<div class="post-metadata">

### Author: ![fbenavides](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@fbenavides](https://pdfjs.community/u/fbenavides)
#### Post date: [February 17, 2021, 11:00pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/3 "2021-02-17T23:00:29Z")

</div>

Hi Logan, thank you for your answer.

I managed to do trigger my custom event with the PdfTron demo. How ever , I didn´t have success with the PDF.js Express demo.

In Pdf.js Express the annotations are not returning actions.

This is my code

WebViewer({  
path: ‘PDFJSExpress/lib’, // path to the PDF.js Express’lib’ folder on your server  
licenseKey: ‘Insert commercial license key here after purchase’,  
initialDoc: ‘WebViewer/samples/viewing/viewing/ejemplo3/test.pdf’,

```
    }, document.getElementById('viewer'))

        .then(instance => {
            const docViewer = instance.docViewer;
            const annotManager = instance.annotManager;
         //PDFTron return actions but PDF.JSExpress don't   
         docViewer.on('annotationsLoaded', () => {
                const annotations = annotManager.getAnnotationsList();
                annotations.forEach(annot => {
		
                    var a = annot.getActions();
                    if (a.U) {
                        if (a.U.length>0) {
                            var act = a.U[0];
                            if (act.elementName == 'URI') {
                                var auri = act.fr;
                                act.onTriggered = function (dispacher, event, owner) {
                                    //Do something
                                }
                            }
                        }
                    }
        
                });
    
                });
           
           
        });
```

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [February 22, 2021, 9:16pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/4 "2021-02-22T21:16:37Z")

</div>

Hi!

Please note that you cannot rely on the minified properties such as `a.U` and `act.fr`, as these may change between versions/builds.

Is the issue that `annot.getActions();` returns an empty array using Express?

---

<div class="post-metadata">

### Author: ![fbenavides](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@fbenavides](https://pdfjs.community/u/fbenavides)
#### Post date: [February 23, 2021, 9:10pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/5 "2021-02-23T21:10:18Z")

</div>

Thank you Logan, I will fix the code to not use the minifield properties.

Yes , in Express annot.getActions() returns an empty array

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/7f285d67e14eebd580809ee7a505a45c342933c7.png)

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 1, 2021, 5:26pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/6 "2021-03-01T17:26:55Z")

</div>

Would you mind sharing the document you are having issues with?

Thanks!

---

<div class="post-metadata">

### Author: ![fbenavides](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@fbenavides](https://pdfjs.community/u/fbenavides)
#### Post date: [March 1, 2021, 9:51pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/7 "2021-03-01T21:51:14Z")

</div>

of course!

[test.pdf](https://pdfjs.community/uploads/short-url/saASr3TCWd4dSPFQ1L30kvavKrw.pdf) (33.6 KB)

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 2, 2021, 4:53pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/8 "2021-03-02T16:53:54Z")

</div>

Thanks @fbenavides !

I can reproduce your issue and will look for a fix today.

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 2, 2021, 5:03pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/9 "2021-03-02T17:03:47Z")

</div>

Hey again,

I found a fix and it will be fixed in the next patch, which I’ll push out either today or tomorrow. I’ll announce it in #announcements so keep an eye out!

Thank you for your patience with this one.

Logan

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 2, 2021, 5:07pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/10 "2021-03-02T17:07:03Z")

</div>



---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 3, 2021, 6:20pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/11 "2021-03-03T18:20:21Z")

</div>



---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 3, 2021, 6:20pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/12 "2021-03-03T18:20:30Z")

</div>

Hey!

This was fixed in 7.3.1

> [@Patch 7.3.1 - Regression Fixes](https://pdfjs.community/t/patch-7-3-1-regression-fixes/559):
>
> Hey guys! As promised, 7.3.1 has been released that fixes a couple issues with the 7.3 release. View the changelog [here](https://pdfjs.express/documentation/changelog/). Thanks! Loga

---

<div class="post-metadata">

### Author: ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)
#### Post date: [March 3, 2021, 6:20pm UTC](https://pdfjs.community/t/custom-trigger-to-hyperlinks-link-and-goto-that-are-already-created-in-original-pdf/505/13 "2021-03-03T18:20:33Z")

</div>


