pdf.js/examples/helloworld/hello.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
2017-02-10 00:53:52 +09:00
// In production, the bundled pdf.js shall be used instead of SystemJS.
Promise.all([SystemJS.import('pdfjs/display/api'),
SystemJS.import('pdfjs/display/global')])
.then(function (modules) {
var api = modules[0], global = modules[1];
// 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.
api.getDocument('helloworld.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);
});
2012-04-13 00:23:38 +09:00
});
});