Containerized REST API for the conversion of PDF documents to images using ImageMagick
2.1K
This repository contains a simple containerized API to convert PDF documents to images using Imagemagick.
The source code is available on Github.
By default, the container listens on port 3000. The port is configurable using the PORT environment variable.
All requests must by send in POST to the /convert endpoint with a multipart/form-data content type. The request must contain a PDF file with the key file. Additional parameters can be sent to customize the conversion process:
format: The format of the output images. Default is jpg.density: The density of the output images. Default is 300.height: The height of the output images. Default is 1000.width: The width of the output images. Default is 1000.background: The background color of the output images. Default is white.quality: The quality of the output images in percentage. Default is 80.page: The page to convert starting at 0. Default is 0.The server returns 200 if the conversion was successful and the images are available in the response body. In case of error, the server returns a 400 status code with a JSON object containing the error message (format: {error: string}).
docker run -p "3000:3000" codeinchq/pdf2img
First page conversion to the default format (WebP)
curl -X POST -F "file=@/path/to/file.pdf" http://localhost:3000/convert -o example.webp
Conversion with custom params (page 2 to JPEG with an orange background):
curl -X POST -F "file=@/path/to/file.pdf" -F "page=1" -F "format=jpg" -F "background=#F60" http://localhost:3000/convert -o example.jpg
A health check is available at the /health endpoint. The server returns a status code of 200 if the service is healthy, along with a JSON object:
{ "status": "up" }
A PHP 8 client is available at on GitHub and Packagist.
This project is licensed under the MIT License - see the LICENSE file for details.
Content type
Image
Digest
sha256:ee008f157…
Size
86.7 MB
Last updated
over 1 year ago
docker pull codeinchq/pdf2img