Hi all,
Product: webviewer
Product Version: 8.12.0
How to intercept relative links/urls in PDF Viewer ?
Thanks.
Vadim.
Hi all,
Product: webviewer
Product Version: 8.12.0
How to intercept relative links/urls in PDF Viewer ?
Thanks.
Vadim.
Hi
Would you be able to share more info about this use case? Or maybe some examples?
Alternatively, you can filter the annotations list for link annotation type and check its link value. You can find more information on how to interact with annotations and AnnotationManager here and here is the Link annotation docs
Hi,
I’ve tried this:
instance.Core.Actions.setCustomOnTriggeredHandler(instance.Core.Actions.URI, (target, event, documentViewer, options) => {
// Doesn't work
if (target instanceof instance.Core.Annotations.Link) {
return;
}
options.originalOnTriggered(target, event, documentViewer);
});
const docViewer = instance.docViewer;
const annotManager = instance.annotManager;
docViewer.on('annotationsLoaded', () => {
const annotations = annotManager.getAnnotationsList();
annotations.forEach(annot => {
if (annot instanceof instance.Core.Annotations.Link) {
// Stops here, but what to do further ?, annot.getActions() returns empty object
debugger
// How to get the path of the annotation, somewhere there's such a pdf path "a/b/my.pdf"
// which is basically a path to other PDF, how to get it ?
}
});
});
Basically what I think I need to do, is somehow get the annotation’s relative link and then create a link (possibly like here Apryse Documentation | Documentation) and add it to the annotation as action, on click it should redirect to the other pdf in the application.
We’ve implemented based on following example:
Webviewer({
...
}, document.getElementById('viewer')).then(instance => {
const { documentViewer, Annotations, annotationManager, Actions } = instance.Core;
documentViewer.addEventListener('annotationsLoaded', () => {
const doc = documentViewer.getDocument();
const annots = annotationManager.getAnnotationsList();
annots.forEach(annot => {
if (annot instanceof Annotations.Link) {
var linkHref = new Actions.URI({
uri: 'https://pdftron.s3.amazonaws.com/downloads/pl/Cheetahs.pdf',
});
annot.addAction('U', linkHref);
}
});
});
Actions.setCustomOnTriggeredHandler(Actions.URI, (target, event, documentViewer, options) => {
if (target instanceof Annotations.Link) {
documentViewer.loadDocument(options.action.uri);
}
});
});
Thanks for help.