Sign inSign up

joanfabregat/pdf2img

By joanfabregat

•Updated over 1 year ago

Containerized REST API for converting PDF documents to images using ImageMagick

Image
API management
1

2.8K

joanfabregat/pdf2img repository overview

⁠PDF to Image Converter API

Build and push Docker Image Version

A lightweight Express.js service that converts PDF files to various image formats base on ImageMagick⁠.

⁠Features

  • Convert PDF files to images (webp, jpg, png, etc.)
  • Configure conversion parameters (density, quality, dimensions, etc.)
  • Simple REST API interface

⁠Requirements

  • Node.js (v14 or higher recommended)
  • ImageMagick (convert command must be available in your PATH)

⁠Installation

  1. Clone the repository:
git clone https://github.com/jfabregat/pdf-to-image.git
cd pdf-to-image
  1. Install dependencies:
npm install
  1. Ensure ImageMagick is installed:
    • Linux: sudo apt-get install imagemagick
    • macOS: brew install imagemagick
    • Windows: Download from ImageMagick website⁠

⁠Usage

⁠Starting the server
npm start

The server will start on port 3000 by default. You can configure the port using the PORT environment variable.

⁠Environment Variables
  • PORT: Server port (default: 3000)
  • VERSION: Application version
  • BUILD_ID: Build identifier
  • COMMIT_SHA: Git commit SHA
⁠API Endpoints
⁠GET /

Returns version and uptime information.

Response:

{
  "upSince": "2025-03-16T10:00:00.000Z",
  "version": "1.0.0",
  "buildId": "12345",
  "commitSha": "abc123"
}
⁠POST /convert

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"

⁠Docker Support

A Dockerfile is provided to containerize the application:

docker build -t pdf-to-image .
docker run -p 3000:3000 pdf-to-image

⁠Security Considerations

  • 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

⁠License

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.

Tag summary

Content type

Image

Digest

sha256:d4ba0b03a…

Size

86.7 MB

Last updated

over 1 year ago

docker pull joanfabregat/pdf2img