UNPKG

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.

72 lines (71 loc) 4.17 kB
#!/usr/bin/env node import { type NormalizedPdfToPngOptions } from './normalizePdfToPngOptions.js'; /** * Help text shown for `--help` and on invalid usage. * Exported so it can be asserted in tests without running the full CLI pipeline. */ export declare const HELP_TEXT = "Usage: pdf-to-png-converter <pdf-file-path> [options]\n\nOptions:\n --output-folder <dir> Folder path where PNG files will be written (required unless --return-metadata-only)\n --viewport-scale <number> Scale factor applied to each page viewport\n --use-system-fonts Attempt to use fonts installed on the host system\n --disable-font-face <true|false> Do not load embedded fonts (true/false)\n --enable-xfa <true|false> Process XFA form data (true/false)\n --pdf-file-password <pwd> Password for encrypted PDFs\n --pages-to-process <n,m,...> Comma-separated list of 1-based page numbers\n --verbosity-level <number> pdfjs verbosity level (0=errors, 1=warnings, 5=infos)\n --return-metadata-only Return page metadata without rendering images\n --process-pages-in-parallel Process pages concurrently\n --concurrency-limit <number> Max concurrent pages (parallel) / worker-pool size (worker threads)\n --render-in-worker-threads Rasterize pages in a pool of worker threads (multi-core)\n --silent Suppress output unless there is an error\n --version Show version\n --help Show this help message"; type ParsedValues = { 'output-folder'?: string; 'viewport-scale'?: string; 'use-system-fonts'?: boolean; 'disable-font-face'?: string; 'enable-xfa'?: string; 'pdf-file-password'?: string; 'pages-to-process'?: string; 'verbosity-level'?: string; 'return-metadata-only'?: boolean; 'return-page-content'?: boolean; 'process-pages-in-parallel'?: boolean; 'concurrency-limit'?: string; 'render-in-worker-threads'?: boolean; silent?: boolean; version?: boolean; help?: boolean; }; /** * Parses a CLI string value as a boolean. * * - `'true'` / `'1'` → `true` * - `'false'` / `'0'` → `false` * - `undefined` → `undefined` (flag not provided) * * @throws {Error} When the value is not a recognised boolean string. */ export declare function parseBoolean(val: string | undefined): boolean | undefined; /** * Parses a comma-separated string of integers into a `number[]`. * * Returns `undefined` when `val` is `undefined` (flag not provided). * * @throws {Error} When any token in the list is not a valid integer. */ export declare function parseNumberList(val: string | undefined): number[] | undefined; /** * Parses raw CLI flags into a validated `NormalizedPdfToPngOptions` plus the positional * `pdfFilePath`. Single source of normalization — downstream {@link executeConversion} * passes the result straight to {@link pdfToPngCore} so the library does NOT re-normalize. * * The CLI only supports stdout-friendly metadata mode (`--return-metadata-only`) or * file-writing image conversion (`--output-folder`). In-memory PNG buffers remain a * library-only capability because the CLI does not serialize page results. */ export declare function buildPdfToPngOptions(values: ParsedValues, positionals: string[]): { pdfFilePath: string; options: NormalizedPdfToPngOptions; }; export declare function executeConversion(pdfFilePath: string, options: NormalizedPdfToPngOptions, logInfo: (...msgs: unknown[]) => void, writeOutput?: (...msgs: unknown[]) => void): Promise<void>; /** * Reads the package version from the adjacent `package.json`. * Throws when `package.json` is missing or malformed so packaging defects surface immediately. */ export declare function getVersion(): string; /** * Main CLI entry point. * * Parses `process.argv`, validates all options up-front through * {@link normalizePdfToPngOptions} via {@link buildPdfToPngOptions}, and delegates to * {@link pdfToPngCore}. Exported so it can be unit-tested without spawning a child process. */ export declare function run(): Promise<void>; export {};