javascript - How to disable hyperlinks within a PDF rendered by PDF.js -
i'm looking pdf.js use in web app. far, it's meeting of our business requirements. however, management has requested have ability disable hyperlinks within pdf. don't have rid of blue text , underline, if user clicks on hyperlink, shouldn't go anywhere.
i've looked through api there , couldn't find it. looked through source code, nothing jumped out @ me comment out in order disable hyperlinks. there way disable hyperlinks contained within pdf?
after great deal of experimentation, found out how modifying source. there block of code begins following:
document.addeventlistener('pagerendered', function (e) {
at end of function before close bracket, add following code:
var allowinternallinks = true; var page = document.getelementbyid('pagecontainer' + pagenumber); var hyperlinks = page.getelementsbytagname('a'); (var i=0; i<hyperlinks.length; i++){ if (!allowinternallinks || hyperlinks[i].classname != 'internallink'){ hyperlinks[i].onclick = function(e) { e.preventdefault(); } } };
what take rendered page, iterate through of hyperlinks on page, , disable them. have added boolean variable allows optionally allow or disallow internal links (i.e. links take user location within document).
Comments
Post a Comment