1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

[api-minor] Use the NodeCanvasFactory/NodeCMapReaderFactory classes as defaults in Node.js environments (issue 11900)

This moves, and slightly simplifies, code that's currently residing in the unit-test utils into the actual library, such that it's bundled with `GENERIC`-builds and used in e.g. the API-code.

As an added bonus, this also brings out-of-the-box support for CMaps in e.g. the Node.js examples.
This commit is contained in:
Jonas Jenwald 2020-06-29 13:18:51 +02:00
parent fe3df495cc
commit 4a7e29865d
10 changed files with 164 additions and 123 deletions

View file

@ -50,14 +50,21 @@ NodeCanvasFactory.prototype = {
var pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");
// Relative path of the PDF file.
var pdfURL = "../../../web/compressed.tracemonkey-pldi-09.pdf";
// Some PDFs need external cmaps.
var CMAP_URL = "../../../node_modules/pdfjs-dist/cmaps/";
var CMAP_PACKED = true;
// Read the PDF file into a typed array so PDF.js can load it.
var rawData = new Uint8Array(fs.readFileSync(pdfURL));
// Loading file from file system into typed array.
var pdfPath =
process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
var data = new Uint8Array(fs.readFileSync(pdfPath));
// Load the PDF file.
var loadingTask = pdfjsLib.getDocument(rawData);
var loadingTask = pdfjsLib.getDocument({
data: data,
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
});
loadingTask.promise
.then(function (pdfDocument) {
console.log("# PDF document loaded.");