pdf-to-png-converter
Version:
Node.js utility to convert PDF file/buffer pages to PNG files/buffers. No build-time compilation required — pre-built native binaries included for all major platforms.
38 lines (37 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.propsToPdfDocInitParams = propsToPdfDocInitParams;
const const_js_1 = require("./const.js");
const normalizePath_js_1 = require("./normalizePath.js");
/**
* Maps a fully-validated `NormalizedPdfToPngOptions` to a pdfjs `DocumentInitParameters`.
*
* Starts from `DOCUMENT_INIT_PARAMS_DEFAULTS` (cMap paths and standard font data URL) and
* overlays the following fields. Because the caller has already run all defaulting through
* `normalizePdfToPngOptions`, this mapper performs **no** fallback resolution — it is a pure
* field rename:
*
* - `verbosityLevel` → `verbosity`
* - `disableFontFace` → `disableFontFace`
* - `useSystemFonts` → `useSystemFonts`
* - `enableXfa` → `enableXfa`
* - `pdfFilePassword` → `password`
*
* The cMap and standard-font asset paths are resolved at call time so that any
* `process.chdir()` between import and invocation is correctly reflected.
*
* @param opts - Already-normalized options.
* @returns A `DocumentInitParameters` object ready to be passed to pdfjs `getDocument()`.
*/
function propsToPdfDocInitParams(opts) {
return {
...const_js_1.DOCUMENT_INIT_PARAMS_DEFAULTS,
cMapUrl: (0, normalizePath_js_1.normalizePath)(const_js_1.CMAP_RELATIVE_URL),
standardFontDataUrl: (0, normalizePath_js_1.normalizePath)(const_js_1.STANDARD_FONTS_RELATIVE_URL),
verbosity: opts.verbosityLevel,
disableFontFace: opts.disableFontFace,
useSystemFonts: opts.useSystemFonts,
enableXfa: opts.enableXfa,
password: opts.pdfFilePassword,
};
}