Answer the question
In order to leave comments, you need to log in
How to use pdf.js in a blog?
Can you please tell me how to use pdf.js in a blog so that the page can be both viewed and downloaded in pdf ?
Answer the question
In order to leave comments, you need to log in
function viewPDF (event) {
var link = encodeURI(event.target.href);
var ifrm= document.createElement('iframe');
var width = 800;
var left = 100;
ifrm.src = link;
/// для примера
ifrm.src = 'http://mozilla.github.io/pdf.js/web/viewer.html?file=http%3A%2F%2Fasync5.org%2Fmoz%2Fpdfjs.pdf';
ifrm.setAttribute('style', 'z-index: 9999;width: '+width+'px; height: 500px; position: fixed; top: 100px; left: '+left+'px;');
var close = document.createElement('button');
close.setAttribute('type', 'button');
close.innerHTML = 'Закрыть';
close.onclick = function() {
document.body.removeChild(ifrm);
document.body.removeChild(close);
}
close.setAttribute('style', 'z-index: 9999;position: fixed; top: 100px; left: '+ (left+width+20) +'px;');
document.body.appendChild(ifrm);
document.body.appendChild(close);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question