How to bind custom trigger to hyperlinks / link and goto that are already created in original PDF

690 views
Skip to first unread message

Nam Tran Quoc

unread,
Apr 22, 2016, 12:49:42 PM4/22/16
to PDFTron WebViewer
Hi All,

We are developing web application that displays PDF documents. Currently the application depends on Adobe ActiveX installed to IE browser. We are planning to use PDFTron WebViewer to replace the PDF add-on. During investigating WebViewer, we have trouble with below scenario:

- In web server, there is folder storing PDF files. Inside of a specific pdf file, there are some hyperlinks / links to other pdf files. The URI is relative path because pdf location is fixed in web server and exposed to client.
- Currently, linked pdf file is opened inside of the add-on once clicking every pdf hyperlink / link. Then there is no way to back the original pdf unless reopening it.
- We are redesigning it by using PDFTron WebViewer, but any relative link is not executed when clicking. However, a web link is opened property in new browser tab. Does WebViewer support to prevent opening a new tab, then add a custom code to the event? E.g. open a link with an iframe that is a child element of current page.

We appreciate and thank you for a help.

Thanks,
Nam Tram

Nam Tran Quoc

unread,
Apr 25, 2016, 1:45:41 PM4/25/16
to PDFTron WebViewer
After looking into the PDF document, we found that GoToR is used to build a link to other documents with relative path. So does PDFTron WebViewer support GoToR action? Because we use AnnotationManager.exportAnnotations method, GoToR actions are not built to the xml format. Pls give us your idea, suggestions or workaround.

Thanks in advance!
Nam Tran

Anatoly Kudrevatukh

unread,
Apr 25, 2016, 8:49:08 PM4/25/16
to PDFTron WebViewer
Hello,

By default WebViewer is only able to perform internal navigation while all external links are opened in a new window. See our forms sample here http://pdftron.com/webviewer/pdfnetjs/samples/form-actions/index.html?doctype=xod

To be able to open GoToR hyperlinks within the same WebViewer instance, you would have to take the following steps:

1) Pre-processing: Iterate over bookmarks in a PDF and add a special labels to GoToR bookmarks
Note: this step can be done in a browser if you are evaluating PDFNet.js solution https://www.pdftron.com/pdfnet/pdfnetjs/index.html
Otherwise if you are going to convert to XOD first (https://www.pdftron.com/webviewer/demo/tutorials/getting-started-converting.html) you can do it on a server at the same time.

2) In WebViewer add link handling code that detects a click on GoToR link that have been labeled in step 1. At this point we can use WebViewer API to open a new document in the same window. https://www.pdftron.com/webviewer/demo/lib/html5/doc/symbols/WebViewerInterface.html#loadDocument

Note: that relative path might not work, since it will be relative to your server root not the PDF. So during the steps 1 or 2 you might want to expand it to correct relative or absolute path.

Let me know if you have further questions. If you let us know more details on the problem are you trying to solve, we might be able to recommend a better approach.

Matt Parizeau

unread,
Dec 20, 2018, 6:32:59 PM12/20/18
to PDFTron WebViewer
WebViewer 3.2 and higher have support for detecting GoToR links but you'll currently still need to add some code to hook them up to open in the same viewer or in a new window. You can do this by extending the onTriggered function of the GoToR action.

Add the following code to your config file:

var gotorOnTrigger = window.Actions.GoToR.prototype.onTriggered;
window.Actions.GoToR.prototype.onTriggered = function(link) {
  gotorOnTrigger.apply(this, arguments);
  // call readerControl.loadDocument or window.open to load the new file
  console.log(this.filename, this.newWindow, this.dest.pagethis.dest.name);
};
Reply all
Reply to author
Forward
0 new messages