4db7330677
Given that browsers/environments without native support for both arrow functions and object shorthand properties are no longer supported in PDF.js, please refer to the compatibility information below, we can now enable a fair number of ESLint rules and also simplify/remove some `.eslintrc` files. With the exception of the `no-alert` cases, all code changes were made automatically by using `gulp lint --fix`. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#browser_compatibility - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#browser_compatibility
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
// Any copyright is dedicated to the Public Domain.
|
|
// http://creativecommons.org/licenses/publicdomain/
|
|
|
|
// Hello world example for browserify.
|
|
|
|
var pdfjsLib = require("pdfjs-dist");
|
|
|
|
var pdfPath = "../learning/helloworld.pdf";
|
|
|
|
// Setting worker path to worker bundle.
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
"../../build/browserify/pdf.worker.bundle.js";
|
|
|
|
// Loading a document.
|
|
var loadingTask = pdfjsLib.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({ scale: 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,
|
|
});
|
|
return renderTask.promise;
|
|
});
|
|
})
|
|
.catch(function (reason) {
|
|
console.error("Error: " + reason);
|
|
});
|