Update (primarily) the Node.js examples to release page resources

Given that Node.js doesn't support Workers, general PDF.js performance will be worse when compared to browsers. In an attempt to improve at least memory usage a little bit, update the Node.js examples to release page resources once parsing is done for that page.
This commit is contained in:
Jonas Jenwald 2021-11-30 13:11:50 +01:00
parent 700eaecddd
commit 487a7ddc7d
4 changed files with 8 additions and 0 deletions

View File

@ -53,6 +53,8 @@ loadingTask.promise
});
console.log("## Text Content");
console.log(strings.join(" "));
// Release page resources.
page.cleanup();
})
.then(function () {
console.log();

View File

@ -103,6 +103,8 @@ const loadingTask = pdfjsLib.getDocument({
);
}
});
// Release page resources.
page.cleanup();
} catch (reason) {
console.log(reason);
}

View File

@ -118,6 +118,8 @@ const loadingTask = pdfjsLib.getDocument({
svgGfx.embedFonts = true;
const svg = await svgGfx.getSVG(opList, viewport);
await writeSvgToFile(svg, getFilePathForPage(pageNum));
// Release page resources.
page.cleanup();
} catch (err) {
console.log(`Error: ${err}`);
}

View File

@ -58,6 +58,8 @@ async function pageLoaded() {
// building SVG and adding that to the DOM
const svg = buildSVG(viewport, textContent);
document.getElementById("pageContainer").appendChild(svg);
// Release page resources.
page.cleanup();
}
document.addEventListener("DOMContentLoaded", function () {