<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src=https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js> </script> </head> <body> <canvas id="canvas" style="border:1px solid black"> </canvas> <script> var pdf = null; PDFJS.disableWorker = true; var pages = new Array(); var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); var scale = 1.5; var canvasWidth = 0; var canvasHeight = 0; var pageStarts = new Array(); pageStarts[0] = 0; var url = 'pdf/PRO1000093000.pdf'; alert(pageStarts); PDFJS.getDocument(url).then(function getPdfHelloWorld(_pdf) { pdf = _pdf; //Render all the pages on a single canvas alert(pdf.numPages); for (var i = 1; i <= pdf.numPages; i++) { pdf.getPage(i).then(function getPage(page) { var viewport = page.getViewport(scale); canvas.width = viewport.width; // changing canvas.width and/or canvas.height auto-clears the canvas canvas.height = viewport.height; page.render({ canvasContext: context, viewport: viewport }); pages[i - 1] = context.getImageData(0, 0, canvas.width, canvas.height); if (canvas.width > canvasWidth) { // calculate the width of the final display canvas canvasWidth = canvas.width; } canvasHeight += canvas.height; // calculate the accumulated with of the final display canvas pageStarts[i] = pageStarts[i - 1] + canvas.height; // save the "Y" starting position of this pages[i] }); } canvas.width = canvasWidth; canvas.height = canvasHeight; // this auto-clears all canvas contents alert(pages.length); for (var i = 0; i < pages.length; i++) { context.putImageData(pages[i], 0, pageStarts[i]); } }); </script> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)