/pdf-worker-service

Python PDF Layer Merging with PyMuPDF (public, AGPL-3.0)

Primary LanguagePythonOtherNOASSERTION

PDF Worker Service

AGPL-3.0 Licensed PDF Processing Service

This is Service B of the Layered Pattern Converter project - a standalone FastAPI service that handles PDF layer processing using PyMuPDF. This service is licensed under AGPL-3.0 to comply with PyMuPDF's licensing requirements.

Overview

This service provides PDF processing capabilities for converting per-page layered PDFs into documents with global layers. It's designed to be called by Service A (the main application) via API.

Features

  • PDF analysis and layer detection
  • Layer merging and PDF manipulation
  • Preview and full document generation
  • Temporary file management and cleanup
  • API key authentication

Requirements

  • Python 3.8+
  • PyMuPDF (AGPL licensed)
  • FastAPI
  • Uvicorn

Installation

  1. Clone this repository
  2. Create a virtual environment:
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Copy .env.example to .env and configure your API key

Usage

Start the service:

python -m uvicorn main:app --host 0.0.0.0 --port 3002 --reload

The service will be available at http://localhost:3002

API Endpoints

  • GET /health - Health check
  • POST /process-pdf - Analyze PDF and detect layers
  • POST /merge-layers - Process PDF and merge layers
  • GET /download/{filename} - Download processed files

Environment Variables

  • PDF_WORKER_API_KEY - API key for authentication (required)

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the LICENSE file for details.

This licensing is required due to the use of PyMuPDF, which is AGPL-licensed. Any service that uses this code must also be made available under AGPL-3.0.

Architecture

This service is part of a two-service architecture designed for license compliance:

  • Service A (Private): Business logic, authentication, payments (proprietary license)
  • Service B (Public): PDF processing with PyMuPDF (AGPL-3.0 license)

The services communicate via HTTP API with API key authentication, maintaining proper license isolation.