@nerem/pdf2png
v1.0.0
Published
Convert PDF files to PNG images with customizable DPI and page selection
Downloads
6
Maintainers
Readme
pdf2png
Convert PDF files to PNG images with customizable DPI and page selection.
Features
- Convert entire PDFs or specific page ranges to PNG images
- Customizable DPI/resolution (default: 150 DPI)
- Progress bar showing conversion status
- TypeScript-based for type safety
- Simple CLI interface
- Uses PDF.js for reliable PDF rendering
Installation
Global Installation (Recommended for CLI usage)
npm install -g pdf2pngLocal Installation
npm install pdf2pngUsage
Basic Usage
Convert all pages of a PDF to PNG images:
pdf2png input.pdf outputThis will create output1.png, output2.png, output3.png, etc. for each page in the PDF.
Custom DPI
Specify a custom DPI for higher or lower resolution output:
# High resolution (300 DPI)
pdf2png input.pdf output --dpi 300
# Low resolution for thumbnails (72 DPI)
pdf2png input.pdf output --dpi 72DPI Reference:
- 72 DPI: Screen resolution, smaller files
- 150 DPI: Default, good balance of quality and file size
- 300 DPI: Print quality, larger files
Page Range Selection
Convert specific pages or page ranges:
# Convert only pages 1-5
pdf2png input.pdf output --pages 1-5
# Convert pages 1, 3, and 5-10
pdf2png input.pdf output --pages 1,3,5-10
# Convert only page 7
pdf2png input.pdf output --pages 7Disable Progress Bar
If you want to suppress the progress bar output:
pdf2png input.pdf output --no-progressFull Example
pdf2png document.pdf page --dpi 300 --pages 1-10,15,20-25This converts pages 1-10, 15, and 20-25 from document.pdf to PNG files at 300 DPI, creating:
page1.pngpage2.png- ...
page10.pngpage15.pngpage20.png- ...
page25.png
CLI Options
Usage: pdf2png [options] <input-pdf> <output-scheme>
Arguments:
input-pdf Input PDF file path
output-scheme Output filename scheme (e.g., "output" creates output1.png, output2.png, ...)
Options:
-V, --version Output the version number
--dpi <number> DPI resolution for output images (default: "150")
--pages <range> Page range to convert (e.g., "1-5,7,10-12")
--no-progress Disable progress bar output
-h, --help Display help for commandRequirements
- Node.js >= 16.0.0
- npm or yarn
Technical Details
This package uses:
- pdf-to-png-converter: Reliable PDF to PNG conversion library built on pdf-poppler
- Commander.js: For CLI argument parsing
- cli-progress: For progress bar display
Development
Setup
# Clone the repository
git clone <repository-url>
cd pdf2png
# Install dependencies
npm install
# Build the project
npm run buildScripts
npm run build: Compile TypeScript to JavaScriptnpm run dev: Run CLI directly with tsx (development mode)
Testing Locally
To test the CLI locally before publishing:
# Link the package globally
npm link
# Now you can use pdf2png command
pdf2png test.pdf output --dpi 300License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Issues
If you encounter any issues or have suggestions, please file an issue on the GitHub repository.
Author
Created with TypeScript and PDF.js
