- Python 97.2%
- Dockerfile 2.8%
| .vscode | ||
| methods | ||
| .coveragerc | ||
| .editorconfig | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| CHANGELOG.md | ||
| CODEOWNERS | ||
| conftest.py | ||
| docker-compose.yaml | ||
| Dockerfile | ||
| LICENSE | ||
| main.py | ||
| poetry.lock | ||
| pyproject.toml | ||
| README.md | ||
| renovate.json | ||
| test_extract_images.py | ||
| test_extract_pages.py | ||
| test_main.py | ||
PDF Pages
A Python worker that converts PDF documents into individual page images using pdf2image. This worker processes PDF files to extract each page as a separate image file, supporting both full document conversion and single page extraction.
Features
- High-quality PDF page extraction using pdf2image
- Batch processing with configurable batch sizes and threading
- Single page extraction support
- Integration with RabbitMQ for message queuing
- MinIO support for object storage
- Docker and Kubernetes deployment ready
- Optimized JPEG output with quality settings
Getting Started
Local Installation
-
Clone the repository:
git clone https://gitlab.com/logius/nldoc/worker/pdf-pages.git cd pdf-pages -
Install Poetry (dependency management):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Install shell plugin:
poetry self add poetry-plugin-shell -
Activate virtual environment:
poetry shell
Running the Worker
Using Docker Compose (Recommended)
-
Ensure Docker and Docker Compose are installed (Installation Guide)
-
Start the services:
docker compose up -
Access the management interfaces:
- RabbitMQ Console:
http://localhost:15672/ - MinIO Console:
http://localhost:9001/
- RabbitMQ Console:
-
Once the
docker compose upcommand has been exited using Ctrl+C, all containers relative to this instance will have shut down automatically.
Running Directly
To run the worker without Docker:
python3 main.py
For configuration options, refer to the Python base worker config.
Configuration
The worker supports the following environment variables:
BATCH_SIZE: Number of pages to process in each batch (default: 20)THREAD_COUNT: Number of threads for parallel processing (default: 20)
Testing
Run the test suite:
pytest
Run tests with coverage:
pytest --cov
How It Works
The worker processes PDF documents through the following steps:
- Job Input: Receives a PDF file and job parameters including
pageCountand optionalpageNumber - Page Extraction: Uses pdf2image to convert PDF pages to high-quality JPEG images
- Batch Processing: For large documents, processes pages in configurable batches
- Storage: Uploads extracted page images to MinIO object storage
- Result Publishing: Returns page metadata including bucket information and file details
Single Page Mode
When a pageNumber parameter is provided, the worker extracts only that specific page:
{
"parameters": {
"pageNumber": 5
}
}
Batch Processing
For documents larger than the configured batch size, the worker automatically splits processing into manageable batches to optimize memory usage and performance.
Deployment
Docker Images
Pre-built Docker images are available in our container registry.
Run the latest version:
docker run --rm registry.gitlab.com/logius/nldoc/worker/pdf-pages:latest
Kubernetes Deployment
We provide a Helm chart for Kubernetes deployment:
name: pdf-pages
version: <version>
repository: https://gitlab.com/api/v4/projects/[project-id]/packages/helm/stable
For detailed configuration options, see the helm/values.yaml file.
Output Format
The worker outputs page images with the following specifications:
- Format: JPEG
- Quality: 95% (optimized for quality)
- Content Type:
image/jpeg - Naming: Sequential page numbers (1.jpg, 2.jpg, etc.)
- Storage Path:
{recordId}/jobs/{jobId}/{pageNumber}.jpg
Documentation
License
This project is licensed under the European Union Public License 1.2 - see LICENSE for details.
Acknowledgements
- pdf2image for PDF to image conversion capabilities