UNPKG

@nova-slides/pdf-to-img

Version:

📃📸 Converts PDFs to images in nodejs

37 lines (36 loc) • 1.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NodeCanvasFactory = void 0; const node_assert_1 = require("node:assert"); const canvas_1 = __importDefault(require("canvas")); class NodeCanvasFactory { /* eslint-disable class-methods-use-this, no-param-reassign */ create(width, height) { (0, node_assert_1.strict)(width > 0 && height > 0, "Invalid canvas size"); const canvas = canvas_1.default.createCanvas(width, height); const context = canvas.getContext("2d"); return { canvas, context, }; } reset(canvasAndContext, width, height) { (0, node_assert_1.strict)(canvasAndContext.canvas, "Canvas is not specified"); (0, node_assert_1.strict)(width > 0 && height > 0, "Invalid canvas size"); canvasAndContext.canvas.width = width; canvasAndContext.canvas.height = height; } destroy(canvasAndContext) { (0, node_assert_1.strict)(canvasAndContext.canvas, "Canvas is not specified"); // Zeroing the width and height cause Firefox to release graphics // resources immediately, which can greatly reduce memory consumption. canvasAndContext.canvas.width = 0; canvasAndContext.canvas.height = 0; canvasAndContext.canvas = null; canvasAndContext.context = null; } } exports.NodeCanvasFactory = NodeCanvasFactory;