generate thumbnail of pdf using pf js

Solutions on MaxInterview for generate thumbnail of pdf using pf js by the best coders in the world

showing results for - "generate thumbnail of pdf using pf js"
Laurie
26 Sep 2019
1function makeThumb(page) {
2  // draw page to fit into 96x96 canvas
3  var vp = page.getViewport(1);
4  var canvas = document.createElement("canvas");
5  canvas.width = canvas.height = 96;
6  var scale = Math.min(canvas.width / vp.width, canvas.height / vp.height);
7  return page.render({canvasContext: canvas.getContext("2d"), viewport: page.getViewport(scale)}).promise.then(function () {
8    return canvas;
9  });
10}
11
12pdfjsLib.getDocument("https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf").promise.then(function (doc) {
13  var pages = []; while (pages.length < doc.numPages) pages.push(pages.length + 1);
14  return Promise.all(pages.map(function (num) {
15    // create a div for each page and build a small canvas for it
16    var div = document.createElement("div");
17    document.body.appendChild(div);
18    return doc.getPage(num).then(makeThumb)
19      .then(function (canvas) {
20        div.appendChild(canvas);
21    });
22  }));
23}).catch(console.error);