A lightweight Express.js service that converts PDF files to various image formats base on ImageMagick.
- Convert PDF files to images (webp, jpg, png, etc.)
- Configure conversion parameters (density, quality, dimensions, etc.)
- Simple REST API interface
- Node.js (v14 or higher recommended)
- ImageMagick (
convert
command must be available in your PATH)
- Clone the repository:
git clone https://github.com/jfabregat/pdf-to-image.git
cd pdf-to-image
- Install dependencies:
npm install
- Ensure ImageMagick is installed:
- Linux:
sudo apt-get install imagemagick
- macOS:
brew install imagemagick
- Windows: Download from ImageMagick website
- Linux:
npm start
The server will start on port 3000 by default. You can configure the port using the PORT
environment variable.
PORT
: Server port (default: 3000)VERSION
: Application versionBUILD_ID
: Build identifierCOMMIT_SHA
: Git commit SHA
Returns version and uptime information.
Response:
{
"upSince": "2025-03-16T10:00:00.000Z",
"version": "1.0.0",
"buildId": "12345",
"commitSha": "abc123"
}
Converts a PDF file to an image.
Request:
- Method: POST
- Content-Type: multipart/form-data
- Body:
file
: PDF file (required)format
: Output image format (default: webp)density
: DPI for conversion (default: 300)background
: Background color (default: white)width
: Output width in pixels (default: 800)height
: Output height in pixels (default: 600)quality
: Output image quality (default: 80%)page
: PDF page to convert (default: 1)
Example:
curl -X POST http://localhost:3000/convert \
-F "[email protected]" \
-F "format=jpg" \
-F "density=200" \
-F "width=1200" \
-F "page=2"
A Dockerfile is provided to containerize the application:
docker build -t pdf-to-image .
docker run -p 3000:3000 pdf-to-image
- This service uses temporary files that are automatically cleaned up after processing
- No authentication is implemented - consider adding authentication for production use
- Verify and validate all input parameters as needed for your environment
Copyright (c) 2025 Joan Fabrégat [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, subject to the conditions in the MIT License.
The Software is provided "as is", without warranty of any kind.