Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

generate thumbnail of pdf using pf js

function makeThumb(page) {
  // draw page to fit into 96x96 canvas
  var vp = page.getViewport(1);
  var canvas = document.createElement("canvas");
  canvas.width = canvas.height = 96;
  var scale = Math.min(canvas.width / vp.width, canvas.height / vp.height);
  return page.render({canvasContext: canvas.getContext("2d"), viewport: page.getViewport(scale)}).promise.then(function () {
    return canvas;
  });
}

pdfjsLib.getDocument("https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf").promise.then(function (doc) {
  var pages = []; while (pages.length < doc.numPages) pages.push(pages.length + 1);
  return Promise.all(pages.map(function (num) {
    // create a div for each page and build a small canvas for it
    var div = document.createElement("div");
    document.body.appendChild(div);
    return doc.getPage(num).then(makeThumb)
      .then(function (canvas) {
        div.appendChild(canvas);
    });
  }));
}).catch(console.error);
Comment

PREVIOUS NEXT
Code Example
Javascript :: all ajaxcomplete event 
Javascript :: mongoose find one and update with new field 
Javascript :: remove jquery 
Javascript :: react routes 
Javascript :: Install react router in react app 
Javascript :: node fs exists 
Javascript :: nuxt router push 
Javascript :: jquery check if clicked outside div 
Javascript :: cryptojs decrypt 
Javascript :: fs , valid path check 
Javascript :: get input type js 
Javascript :: jquery animation 
Javascript :: How to get all input fields inside div with JavaScript 
Javascript :: javascript check if array has duplicates 
Javascript :: datatable giving default width to colums 
Javascript :: javascript function required arguments 
Javascript :: js propagation stop 
Javascript :: capitalize first letter after character javascript 
Javascript :: array chaing in js 
Javascript :: uncaught evalerror: refused to evaluate a string as javascript because 
Javascript :: how to create a global variable in vue 
Javascript :: js get object keys 
Javascript :: how to check if a json object is empty 
Javascript :: how to add button react native app.js 
Javascript :: login page link shopify 
Javascript :: js remove property from object 
Javascript :: on click jquery 
Javascript :: mongoose find by and delete 
Javascript :: npm http status codes 
Javascript :: add css class to html in js 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =