mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Adds/modifies examples for node.js and webpack.
This commit is contained in:
parent
9228e1ffcf
commit
79c2f69c32
15 changed files with 170 additions and 19 deletions
32
examples/webpack/main.js
Normal file
32
examples/webpack/main.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
// Hello world example for webpack.
|
||||
|
||||
require('pdfjs-dist');
|
||||
|
||||
var pdfPath = '../helloworld/helloworld.pdf';
|
||||
|
||||
// It is also possible to disable workers via `PDFJS.disableWorker = true`,
|
||||
// however that might degrade the UI performance in web browsers.
|
||||
|
||||
// Loading a document.
|
||||
var loadingTask = PDFJS.getDocument(pdfPath);
|
||||
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);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue