1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

[api-minor] Move the canvasFactory option into getDocument

Rather than repeatedly initializing a `canvasFactory`-instance for every page, move it to the document-level instead.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
This commit is contained in:
Jonas Jenwald 2023-03-01 09:07:16 +01:00 committed by GitHub
parent 2da2ac492e
commit f42a2e8451
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 32 deletions

View file

@ -58,6 +58,8 @@ const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL =
"../../../node_modules/pdfjs-dist/standard_fonts/";
const canvasFactory = new NodeCanvasFactory();
// Loading file from file system into typed array.
const pdfPath =
process.argv[2] || "../../../web/compressed.tracemonkey-pldi-09.pdf";
@ -69,6 +71,7 @@ const loadingTask = pdfjsLib.getDocument({
cMapUrl: CMAP_URL,
cMapPacked: CMAP_PACKED,
standardFontDataUrl: STANDARD_FONT_DATA_URL,
canvasFactory,
});
(async function () {
@ -79,7 +82,6 @@ const loadingTask = pdfjsLib.getDocument({
const page = await pdfDocument.getPage(1);
// Render the page on a Node canvas with 100% scale.
const viewport = page.getViewport({ scale: 1.0 });
const canvasFactory = new NodeCanvasFactory();
const canvasAndContext = canvasFactory.create(
viewport.width,
viewport.height
@ -87,7 +89,6 @@ const loadingTask = pdfjsLib.getDocument({
const renderContext = {
canvasContext: canvasAndContext.context,
viewport,
canvasFactory,
};
const renderTask = page.render(renderContext);