On Wednesday, June 24, 2015 at 3:48:27 PM UTC-5, Will Herrmann wrote:
> I'm looking into PDF.js for use in a web app. So far, it's meeting all of our business requirements. However, management has requested that we have the ability to disable hyperlinks within the PDF. We don't necessarily have to get rid of the blue text and underline, but if the user clicks on the hyperlink, it shouldn't go anywhere.
>
> I've looked carefully through what API there is and couldn't find anything for it. Is there any way to disable hyperlinks contained within a PDF?
I figured it out how to do it by modifying the source. There is a block of code that begins with the following:
document.addEventListener('pagerendered', function (e) {
At the end of the function before the close bracket, add the following code:
var allowInternalLinks = true;
var page = document.getElementById('pageContainer' + pageNumber);
var hyperlinks = page.getElementsByTagName('a');
for (var i=0; i<hyperlinks.length; i++){
if (!allowInternalLinks || hyperlinks[i].className != 'internalLink'){
hyperlinks[i].onclick = function(e) {
e.preventDefault();
}
}
};
What this does is take the rendered page, iterate through all of the hyperlinks on that page, and disable them. There is a boolean variable that allows you to optionally allow or disallow internal links.
I would be willing to polish this code up and submit it to PDF.js as an actual feature within the product. Is this something that might be desirable in the product? If so, how should I go about doing that?