Modular PDF Engine

Overview

A modular JSON→PDF generation engine designed to guarantee a consistent corporate identity (CI) across all services. The system runs as a console-based microservice: it consumes JSON via piped stdin, renders PDFs through service‑specific plugins, and returns Base64‑encoded output to stdout. This makes it easy to embed in web servers, cron jobs, CI pipelines, and legacy PHP systems.

Motivation

Different services generated PDFs independently, causing duplicated logic and inconsistent branding. This project establishes a single, CI‑enforced pipeline where each service can extend functionality safely via its own plugin—without modifying the core engine.

Features

Architecture

The engine follows a modular pipeline: validate → sanitize → identify plugin → load plugin → render → encode → output. The core enforces CI rules, security checks, and error handling; plugins implement only their content logic.

Data Flow

1. Input Handling

2. Sanitisation & Validation

3. Plugin Lookup

4. Execution Model Plugins must extend an abstract PDF class and implement:

byte[] execute(String inputJson)

This supports multiple rendering libraries while enforcing CI rules.

5. Rendering

6. Output Response

{
  "data": "<base64>",
  "exitcode": 0
}

7. Logging

Architecture Diagram

JSON (stdin)
   │
┌──┴───────────────────┐
│ Validate & Sanitize │
└──┬───────────────────┘
   │ Determine plugin
   ▼
┌──────────────────────┐
│ Plugin Lookup + HMAC │
└──┬───────────────────┘
   │ Reflection load
   ▼
┌──────────────────────┐
│ Plugin Execution     │
└──┬───────────────────┘
   │ PDF bytes
   ▼
┌──────────────────────┐
│ Encode (Base64)      │
└──┬───────────────────┘
   │
   ▼
JSON Output + Logging

Key Decisions

Reflection‑based Plugin Architecture

Abstract CI Base Class

HMAC Verification

Optional AES‑GCM Encryption

Structured Output Format

Limitations / Lessons Learned

Your Contributions

Post‑Project Enhancements

Impact

A single unified PDF engine replaced multiple inconsistent in‑house generators, reduced maintenance costs, and ensured strict CI compliance across all departments.

← Back to all skills