Loading document…
Loading document…
<script>window.pdfSrc = \'/media/uploads/your-file.pdf\';</script> '
+ 'to the content field.';
return;
}
// Wire up download button now we have a path
downloadBtn.href = PDF_URL;
downloadBtn.style.display = 'inline-block';
pdfjsLib.GlobalWorkerOptions.workerSrc =
'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
function renderPage(pdf, pageNum) {
return pdf.getPage(pageNum).then(function (page) {
var naturalViewport = page.getViewport({ scale: 1 });
var scale = (container.clientWidth / naturalViewport.width) * (window.devicePixelRatio || 1);
var viewport = page.getViewport({ scale: scale });
var canvas = document.createElement('canvas');
canvas.className = 'pdf-page-canvas';
canvas.width = viewport.width;
canvas.height = viewport.height;
canvas.style.width = container.clientWidth + 'px';
canvas.style.height = Math.round(viewport.height / (window.devicePixelRatio || 1)) + 'px';
container.appendChild(canvas);
return page.render({
canvasContext: canvas.getContext('2d'),
viewport: viewport
}).promise;
});
}
pdfjsLib.getDocument(PDF_URL).promise.then(function (pdf) {
statusEl.remove();
var chain = Promise.resolve();
for (var i = 1; i <= pdf.numPages; i++) {
chain = chain.then(renderPage.bind(null, pdf, i));
}
return chain;
}).catch(function () {
statusEl.innerHTML =
'Unable to load the document. ' +
'Download the PDF instead.';
});
}());