npm package: @nerem/pdf2png
Description: Convert PDF files to PNG images with customizable DPI and page selection
Author: Felix Kammerlander
Latest version: 1.0.0

# 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)

```bash
npm install -g pdf2png
```

### Local Installation

```bash
npm install pdf2png
```

## Usage

### Basic Usage

Convert all pages of a PDF to PNG images:

```bash
pdf2png input.pdf output
```

This 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:

```bash
# High resolution (300 DPI)
pdf2png input.pdf output --dpi 300

# Low resolution for thumbnails (72 DPI)
pdf2png input.pdf output --dpi 72
```

**DPI 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:

```bash
# 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 7
```

### Disable Progress Bar

If you want to suppress the progress bar output:

```bash
pdf2png input.pdf output --no-progress
```

### Full Example

```bash
pdf2png document.pdf page --dpi 300 --pages 1-10,15,20-25
```

This converts pages 1-10, 15, and 20-25 from `document.pdf` to PNG files at 300 DPI, creating:
- `page1.png`
- `page2.png`
- ...
- `page10.png`
- `page15.png`
- `page20.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 command
```

## Requirements

- 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

```bash
# Clone the repository
git clone <repository-url>
cd pdf2png

# Install dependencies
npm install

# Build the project
npm run build
```

### Scripts

- `npm run build`: Compile TypeScript to JavaScript
- `npm run dev`: Run CLI directly with tsx (development mode)

### Testing Locally

To test the CLI locally before publishing:

```bash
# Link the package globally
npm link

# Now you can use pdf2png command
pdf2png test.pdf output --dpi 300
```

## License

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