This project provides a FastAPI-based web service to convert PDF files to images using the pdf2image
library and poppler
for PDF rendering.
- Convert PDF files to PNG images.
- Update DPI setting dynamically via API.
- Generate unique filenames using UUID.
- Python 3.9.16
- FastAPI
- pdf2image
- Poppler
-
Clone the repository:
git clone https://github.com/PongpreechaSuea/PDF2Image.git cd PDF2Image
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages (
requirements.txt
):pip install -r requirements.txt
Update the src/config.py
file with your desired settings:
POPPLER = ...
RESULTS = ...
DPI = ...
HOST = "localhost"
PORT = ...
BASE_URL = f"http://{HOST}:{PORT}/static/"
Start the FastAPI server:
python ./app.py # http://localhost:3000/docs
or
uvicorn src.main:app --host localhost --port 3000
- Endpoint: /convert/pdf2image
- Method: POST
- Description: Converts a PDF file to PNG images.
- Request: multipart/form-data
- file: The PDF file to convert.
- Response:
{ "message": "File converted successfully", "file_name": "example.pdf", "file_content_type": "application/pdf", "file_urls": [ "http://localhost:3000/static/image_<uuid1>.png", "http://localhost:3000/static/image_<uuid2>.png" ] }
- Endpoint: /setting/dpi
- Method: PUT
- Description: Updates the DPI setting used for PDF to image conversion.
- Request: URL query parameter
- dpi: The new DPI value.
- Response:
{ "message": "DPI updated successfully", "new_dpi": 300 }