S
S
Sergey Alpeev2014-08-01 09:20:46
JavaScript
Sergey Alpeev, 2014-08-01 09:20:46

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 ?
9afbce70dde6de8431c51ecf5e045de137ebaadd

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Push Pull, 2014-08-01
@deadbyelpy

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);
}

it remains only to hang this function on onclick on your links

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question