• Python 97.2%
  • Dockerfile 2.8%
Find a file
2025-12-31 10:13:21 +00:00
.vscode fix: compatibility 2024-04-30 18:49:13 +02:00
methods chore: fixed unit test with new bucket paths 2025-10-31 17:01:23 +01:00
.coveragerc chore: added tests for 100% coverage 2025-01-02 08:35:23 +01:00
.editorconfig chore: set .editorconfig 2025-04-21 23:20:24 +00:00
.gitignore feat: set up tests, force first automated release 2024-04-03 17:24:12 +02:00
.gitlab-ci.yml fix: removed helm-package step 2025-10-21 17:39:17 +02:00
CHANGELOG.md chore(release): 2.1.1 2025-12-31 10:07:53 +00:00
CODEOWNERS chore: set CODEOWNERS 2025-04-22 00:26:03 +00:00
conftest.py feat: set up tests, force first automated release 2024-04-03 17:24:12 +02:00
docker-compose.yaml chore: removed minio-init container now that baseworker upserts buckets 2025-12-03 13:26:40 +01:00
Dockerfile feat(deps): python 3.14.2 and kimiworker 8.0.3 2025-12-30 16:28:07 +01:00
LICENSE chore: add license 2025-04-15 00:16:14 +02:00
main.py feat!: use configurable bucket names 2025-12-22 15:06:07 +01:00
poetry.lock fix(deps): update dependency kimiworker to v8.0.4 2025-12-31 09:56:33 +00:00
pyproject.toml chore(release): 2.1.1 2025-12-31 10:07:53 +00:00
README.md docs: update readme 2025-08-20 00:09:20 +02:00
renovate.json fix(deps): kimiworker 4.15.2 2025-09-11 13:26:11 +02:00
test_extract_images.py chore: removed type checking from unit test 2025-12-23 11:50:27 +01:00
test_extract_pages.py chore: fixed unit test with new bucket paths 2025-10-31 17:01:23 +01:00
test_main.py feat!: use configurable bucket names 2025-12-22 15:06:07 +01:00

PDF Pages

pipeline status coverage report Latest Release

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

  1. Clone the repository:

    git clone https://gitlab.com/logius/nldoc/worker/pdf-pages.git
    cd pdf-pages
    
  2. Install Poetry (dependency management):

    curl -sSL https://install.python-poetry.org | python3 -
    
  3. Install dependencies:

    poetry install
    
  4. Install shell plugin:

    poetry self add poetry-plugin-shell
    
  5. Activate virtual environment:

    poetry shell
    

Running the Worker

  1. Ensure Docker and Docker Compose are installed (Installation Guide)

  2. Start the services:

    docker compose up
    
  3. Access the management interfaces:

    • RabbitMQ Console: http://localhost:15672/
    • MinIO Console: http://localhost:9001/
  4. Once the docker compose up command 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:

  1. Job Input: Receives a PDF file and job parameters including pageCount and optional pageNumber
  2. Page Extraction: Uses pdf2image to convert PDF pages to high-quality JPEG images
  3. Batch Processing: For large documents, processes pages in configurable batches
  4. Storage: Uploads extracted page images to MinIO object storage
  5. 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