2015-12-22 04:46:50 +09:00
|
|
|
// Any copyright is dedicated to the Public Domain.
|
|
|
|
// http://creativecommons.org/licenses/publicdomain/
|
|
|
|
|
|
|
|
// Hello world example for webpack.
|
|
|
|
|
2016-03-29 06:44:27 +09:00
|
|
|
var pdfjsLib = require('pdfjs-dist');
|
2015-12-22 04:46:50 +09:00
|
|
|
|
|
|
|
var pdfPath = '../helloworld/helloworld.pdf';
|
|
|
|
|
2016-04-13 22:24:25 +09:00
|
|
|
// Setting worker path to worker bundle.
|
2018-02-14 22:49:24 +09:00
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
|
|
'../../build/webpack/pdf.worker.bundle.js';
|
2016-04-13 22:24:25 +09:00
|
|
|
|
2015-12-22 04:46:50 +09:00
|
|
|
// Loading a document.
|
2016-03-29 06:44:27 +09:00
|
|
|
var loadingTask = pdfjsLib.getDocument(pdfPath);
|
2015-12-22 04:46:50 +09:00
|
|
|
loadingTask.promise.then(function (pdfDocument) {
|
|
|
|
// Request a first page
|
|
|
|
return pdfDocument.getPage(1).then(function (pdfPage) {
|
|
|
|
// Display page on the existing canvas with 100% scale.
|
|
|
|
var viewport = pdfPage.getViewport(1.0);
|
|
|
|
var canvas = document.getElementById('theCanvas');
|
|
|
|
canvas.width = viewport.width;
|
|
|
|
canvas.height = viewport.height;
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
var renderTask = pdfPage.render({
|
|
|
|
canvasContext: ctx,
|
|
|
|
viewport: viewport
|
|
|
|
});
|
|
|
|
return renderTask.promise;
|
|
|
|
});
|
|
|
|
}).catch(function (reason) {
|
|
|
|
console.error('Error: ' + reason);
|
|
|
|
});
|