UNPKG

pdf-to-png-converter

Version:

Node.js utility to convert PDF file/buffer pages to PNG files/buffers with no native dependencies.

27 lines (26 loc) 1.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.comparePNG = comparePNG; const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const png_visual_compare_1 = __importDefault(require("png-visual-compare")); /** * Compares a PNG image with an expected PNG image. * If the expected image does not exist, it creates it by copying the actual image. * @param actualFile - The path or buffer of the actual PNG image. * @param expectedFile - The path of the expected PNG image. * @param opts - Optional compare options. * @returns A promise that resolves to the comparison result. */ function comparePNG({ actualFile, expectedFile, createExpectedFileIfMissing, opts, }) { if (createExpectedFileIfMissing && !(0, node_fs_1.existsSync)(expectedFile)) { const expectedFileDir = (0, node_path_1.parse)(expectedFile).dir; (0, node_fs_1.mkdirSync)(expectedFileDir, { recursive: true }); const actualBuffer = typeof actualFile === 'string' ? (0, node_fs_1.readFileSync)(actualFile) : actualFile; (0, node_fs_1.writeFileSync)(expectedFile, actualBuffer); } return (0, png_visual_compare_1.default)(actualFile, expectedFile, opts); }