2011-09-26 23:28:16 +03:00
|
|
|
'use strict';
|
2011-09-14 17:34:29 -07:00
|
|
|
|
2017-02-09 09:53:52 -06:00
|
|
|
// In production, the bundled pdf.js shall be used instead of SystemJS.
|
2017-05-10 18:28:18 -05:00
|
|
|
Promise.all([System.import('pdfjs/display/api'),
|
|
|
|
System.import('pdfjs/display/global'),
|
2017-07-29 22:47:46 +02:00
|
|
|
System.import('pdfjs/display/network'),
|
2017-05-10 18:28:18 -05:00
|
|
|
System.resolve('pdfjs/worker_loader')])
|
2017-02-09 09:53:52 -06:00
|
|
|
.then(function (modules) {
|
2017-09-05 20:47:14 +08:00
|
|
|
var api = modules[0], global = modules[1], network = modules[2];
|
2018-02-04 19:32:47 +01:00
|
|
|
api.setPDFNetworkStreamFactory((params) => {
|
|
|
|
return new network.PDFNetworkStream(params);
|
|
|
|
});
|
2017-09-05 20:47:14 +08:00
|
|
|
|
2015-12-16 15:03:06 -06:00
|
|
|
// In production, change this to point to the built `pdf.worker.js` file.
|
2017-07-29 22:47:46 +02:00
|
|
|
global.PDFJS.workerSrc = modules[3];
|
2015-12-16 15:03:06 -06:00
|
|
|
|
|
|
|
// 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);
|
2011-09-14 17:34:29 -07:00
|
|
|
|
2015-12-16 15:03:06 -06:00
|
|
|
// 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;
|
2011-09-14 17:34:29 -07:00
|
|
|
|
2015-12-16 15:03:06 -06:00
|
|
|
// Render PDF page into canvas context.
|
|
|
|
var renderContext = {
|
|
|
|
canvasContext: context,
|
|
|
|
viewport: viewport
|
|
|
|
};
|
|
|
|
page.render(renderContext);
|
|
|
|
});
|
2012-04-12 08:23:38 -07:00
|
|
|
});
|
2011-09-14 17:34:29 -07:00
|
|
|
});
|