d53093045a
Given the amount of work put into removing `require`-calls from the code-base, let's ensure that new ones aren't accidentally added in the future. Note that we still have a couple of files where `require` is being used, in particular: - The Node.js examples, however those will be updated to use `import` in PR 17081. - The Webpack examples, and related support files, however I unfortunately don't know enough about Webpack to be able to update those. (Hopefully users of that code will help out here, once version `4` is released.) - The `statcmp`-tool, since *some* of those `require`-calls cannot be converted to `import` without other code changes (and that file is only used during benchmarking). Please find additional details at https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// Any copyright is dedicated to the Public Domain.
|
|
// http://creativecommons.org/licenses/publicdomain/
|
|
|
|
/* eslint-disable import/no-commonjs */
|
|
|
|
// Hello world example for webpack.
|
|
|
|
const pdfjsLib = require("pdfjs-dist");
|
|
|
|
const pdfPath = "../learning/helloworld.pdf";
|
|
|
|
// Setting worker path to worker bundle.
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
"../../build/webpack/pdf.worker.bundle.js";
|
|
|
|
// Loading a document.
|
|
const 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.
|
|
const viewport = pdfPage.getViewport({ scale: 1.0 });
|
|
const canvas = document.getElementById("theCanvas");
|
|
canvas.width = viewport.width;
|
|
canvas.height = viewport.height;
|
|
const ctx = canvas.getContext("2d");
|
|
const renderTask = pdfPage.render({
|
|
canvasContext: ctx,
|
|
viewport,
|
|
});
|
|
return renderTask.promise;
|
|
});
|
|
})
|
|
.catch(function (reason) {
|
|
console.error("Error: " + reason);
|
|
});
|