JSFiddle - React, Tailwind, and code Playground
by vikikamath
HTML
<script src="https://rawgit.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<canvas id="the-canvas" style="border:1px solid black;"/>
JavaScript
'use strict';
// In production, the bundled pdf.js shall be used instead of RequireJS.
//require.config({paths: {'pdfjs': '../../src'}});
//require(['pdfjs/display/api', 'pdfjs/display/global'], function (api, global) {
// In production, change this to point to the built `pdf.worker.js` file.
//global.PDFJS.workerSrc = '../../src/worker_loader.js';
// Fetch the PDF document from the URL using promises.
PDFJS.getDocument('https://www.pdf995.com/samples/pdf.pdf').then(function (pdf) {
// Fetch the page.
pdf.getPage(1).then(function (page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions.
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context.
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
});
//});