Understand the pdf-to-png-converter architecture
mainThe pdf-to-png-converter is a Node.js 22.13+ CommonJS library and CLI designed to convert PDF pages into PNGs. It uses pdfjs-dist with @napi-rs/canvas for rendering.
Core Components
- Library API: The primary entry point is
pdfToPng(), which orchestrates the conversion pipeline, including option normalization, input handling, and scheduling. - CLI: An adapter that parses arguments and delegates to the core
pdfToPng()function. - Execution Modes: The library supports different rendering strategies depending on your performance and resource needs:
- Metadata-only: Fast mode that only extracts page dimensions and rotation without rendering pixels.
- Main-thread (Default): Uses an ordered scheduler with a window of 3, allowing async encoding/writing to overlap with the next render.
- Parallel (Main-thread): Uses
processPagesInParallel: trueto run a specific number of tasks in flight on the main thread. - Worker Threads: Uses
renderInWorkerThreads: trueto spawn a dynamic worker pool. This is the most performant mode for heavy workloads as it offloads rendering to separate threads.