How can i render all pdf pages in canvas using pdf.js


#1

I am trying to render a pdf file using Mozilla pdf.js.I have succeeded in displaying only one page but i want to display all the pages in the pdf. Below is my code:

PDFJS.workerSrc = ‘/packages/pascoual_pdfjs/build/pdf.worker.js’;
console.log(PDFJS)
//PDFJS.workerSrc = ‘/.meteor/local/build/programs/web.browser/packages/pascoual_pdfjs/build/pdf.worker.js’;
var url = ‘/FYPS/seminars/html5_tutorial.pdf’;
PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
// Fetch the first page
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5 ;
var viewport = page.getViewport(scale);

// Prepare canvas using PDF page dimensions
var canvas = document.getElementById(‘pdfcanvas’);
var context = canvas.getContext(‘2d’);
canvas.height = viewport.height;
canvas.width = viewport.width;

// Render PDF page into canvas context
page.render({canvasContext: context, viewport: viewport}).promise.then(function () {
console.log(‘rendered’);

});
});
});