javascript - How to display whole PDF (not only one page) with PDF.JS? -


i've created demo:

http://polishwords.com.pl/dev/pdfjs/test.html

it displays 1 page. display pages. 1 below another, or place buttons change page or better load standard controls of pdf.js in firefox. how acomplish this?

pdfjs has member variable numpages, you'd iterate through them. but it's important remember getting page in pdf.js asynchronous, order wouldn't guaranteed. you'd need chain them. along these lines:

var currpage = 1; //pages 1-based not 0-based var numpages = 0; var thepdf = null;  //this start pdfjs.getdocument(url).then(function(pdf) {          //set pdfjs global object (so can access in our page functions         thepdf = pdf;          //how many pages has         numpages = pdf.numpages;          //start first page         pdf.getpage( 1 ).then( handlepages ); });    function handlepages(page) {     //this gives page's dimensions @ full scale     var viewport = page.getviewport( 1 );      //we'll create canvas each page draw on     var canvas = document.createelement( "canvas" );     canvas.style.display = "block";     var context = canvas.getcontext('2d');     canvas.height = viewport.height;     canvas.width = viewport.width;      //draw on canvas     page.render({canvascontext: context, viewport: viewport});      //add web page     document.body.appendchild( canvas );      //move next page     currpage++;     if ( thepdf !== null && currpage <= numpages )     {         thepdf.getpage( currpage ).then( handlepages );     } } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -