Skip to content

About

Lightweight API for HTML-to-PDF conversion and PKCS#12 digital signing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Paperforge

Paperforge is a lightweight, self-hosted HTTP API for generating and digitally signing PDF documents. It renders HTML templates with Jinja2, converts them to PDF with WeasyPrint, and applies digital signatures using PKCS#12 (PFX) certificates.

Features

  • HTML to PDF conversion
  • Isolated worker pool for rendering and signing (lazy on-demand imports, idle shutdown)
  • Jinja2 template rendering
  • Multiple uploaded assets (CSS, images, fonts, etc.)
  • PDF digital signing
  • Multiple sequential signatures
  • Optional single text stamp to replace an anchor placeholder
  • Simple HTTP API
  • Docker-friendly
  • Optional API key authentication

Installation

Docker

Run the published image from GitHub Container Registry:

docker run \
  -p 8000:8000 \
  ghcr.io/sergiors/paperforge:latest

With an API key configured:

docker run \
  -p 8000:8000 \
  -e API_KEY=my-secret-api-key \
  ghcr.io/sergiors/paperforge:latest

Build from source

docker build -t paperforge .
docker run -p 8000:8000 paperforge

Docker Compose

docker compose up -d

Environment variables

Variable Description
API_KEY Optional API key. When set, requests must include it in the Authorization header.
TZ Optional timezone. Defaults to UTC. Any valid IANA timezone identifier (e.g. Europe/Rome, America/Sao_Paulo, Asia/Tokyo).
WORKER_COUNT Maximum number of worker processes for rendering and signing. Defaults to 2; must be at least 1.
WORKER_IDLE_TIMEOUT Seconds without pool activity before the worker processes shut down. Defaults to 60; must be greater than 0.
UVICORN_LOOP Uvicorn event loop implementation: auto, asyncio, or uvloop. Defaults to auto.

Authentication is disabled when API_KEY is not configured.

Authentication

When API_KEY is configured, every request must include it as a Bearer token:

Authorization: Bearer <API_KEY>

API

Convert HTML to PDF

POST /convert/html

Converts an uploaded HTML document to PDF.

The request is multipart/form-data with the following fields:

  • files (required) — one or more files. Exactly one must be named index.html; it is the document entry point. Additional files (CSS, images, fonts, etc.) are available by relative path.
  • context (optional) — a JSON object serialized as a string. When provided, index.html is rendered as a Jinja2 template using the object as its context.
curl \
  --request POST http://localhost:8000/convert/html \
  --header "Authorization: Bearer my-secret-api-key" \
  --form files=@index.html \
  --form files=@style.css \
  --form 'context={"name":"Sergio","company":"Paperforge"}' \
  --output document.pdf

Sign PDF

POST /pdf/sign

Digitally signs an uploaded PDF with one or more PKCS#12 certificates.

The request is multipart/form-data with the following fields:

  • files (required) — exactly one PDF document and one or more PKCS#12 (.p12/.pfx) certificates.
  • signers (required) — a JSON array serialized as a string. Each object references an uploaded certificate by filename and provides its passphrase. Signatures are applied sequentially in order.
  • stamp (optional) — a JSON object serialized as a string, with non-empty anchor and text strings. The anchor must occur exactly once in the PDF. The placeholder is replaced with the provided text before signing. Text is centered at the anchor in 8-point black Helvetica, supports multiple lines, and has no background, border, or icon. The document author is responsible for reserving enough space.
curl \
  --request POST http://localhost:8000/pdf/sign \
  --header "Authorization: Bearer my-secret-api-key" \
  --form files=@document.pdf \
  --form files=@company.p12 \
  --form 'signers=[{"file":"company.p12","passphrase":"secret"}]' \
  --form 'stamp={"anchor":"SIGN HERE","text":"Signed by Alice\nDirector"}' \
  --output signed.pdf

A 400 response is returned for invalid stamp JSON or shape, a missing or ambiguous anchor, text that does not fit, or a signed, encrypted, or unreadable PDF.

Error Responses

The API returns standard HTTP status codes. Failures are returned as JSON error responses with a descriptive message.

License

GNU General Public License v3.0 — see LICENSE for details.

About

Lightweight API for HTML-to-PDF conversion and PKCS#12 digital signing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages