Design and Comparison
This page summarises why pidief is built the way it is and how it compares with other PDF tools.
Goal
One self-hosted tool, as a CLI and an HTTP API, that covers what business applications need from PDFs (contracts and documents from HTML templates, reports with long tables, statements, receipts, phone scans, previews, merge/split/rotate, watermarks, passwords, PDF/A), with no licensing traps.
Other tools at a glance
| Tool | Strengths | Gaps | License notes |
|---|---|---|---|
| QuestPDF (.NET) | Fluent C# layout, repeated table headers, PDF/A | No HTML/CSS input, no rasterizing | Community license free only below USD 1M annual revenue |
| Gotenberg (Go) | Chromium + LibreOffice behind REST, header/footer templates, wait conditions | Large image (~1.5-2 GB), no PDF to image, no CLI | MIT |
| PDFsharp / MigraDoc (.NET) | Low-level PDF writing, merge | No HTML, no rasterizing | Moved to AGPL in 6.5 |
| wkhtmltopdf | Simple single binary | Archived in 2023, old WebKit, buggy table headers | LGPL-3 |
| WeasyPrint (Python) | Strong CSS Paged Media, PDF/A, PDF/UA | No JavaScript, partial flex/grid | BSD-3 |
| Playwright/Puppeteer (Chromium) | Highest HTML/CSS/JS fidelity, header/footer templates | No PDF/A, passwords or manipulation | Apache-2.0, Chromium BSD |
| pdfcpu (Go) | Pure Go merge, split, rotate, watermark, encryption | No rasterizing, no HTML, no PDF/A | Apache-2.0 |
| qpdf (C++) | Structural transforms, encryption, repair | No rasterizing, HTML or watermarks | Apache-2.0 |
| Ghostscript | PDF/A, downsampling, rasterizing | Heavy | AGPL-3 or commercial |
| Stirling-PDF | Web UI and API for every operation | Very large (~1-2 GB), an application rather than a component | Core MIT, some features commercial |
| iText (Java/.NET) | Very mature, PDF/A, PDF/UA, signatures | — | AGPL-3 or commercial |
| PDFium | Chrome-quality rasterizing and text extraction | No layout or creation | BSD-3 / Apache-2.0 |
| MuPDF / Poppler | Fast rasterizing | — | AGPL / GPL |
What pidief takes from each
- Gotenberg: the multipart API (a main
index.htmlplus fonts, images and CSS uploaded next to it),waitForSelector/waitForExpression/waitDelay, header/footer templates, per-request timeouts, health endpoints and Prometheus metrics. pidief adds a small image (no LibreOffice), a CLI, PDF to image, watermarks, passwords, PDF/A-2b, one switch to block external resources, and reuse of one Chromium process. - Playwright/Chromium: the print engine itself.
- WeasyPrint/QuestPDF: PDF/A-2b as an output option, metadata written at creation time, a ready-made "Sayfa X / Y" footer.
- pdfcpu: the page selection syntax (
1-3,5,!2,even,odd,l-1) and watermark/stamp parameters (position, scale, opacity, rotation). - PDFium: rasterizing (thumbnails, previews) and text extraction.
- Stirling-PDF: "everything in one tool", but as a service or component without a UI.
Why Go
Mature, permissively licensed PDF manipulation (pdfcpu, Apache-2.0) and rasterizing (PDFium as WebAssembly, run from pure Go) both exist in Go without cgo. That means the same static binary can be built for linux/amd64 and linux/arm64, with low memory use and Chromium control through chromedp.
Architecture
┌──────────── pidief (single Go binary) ─────────┐
CLI ───────▶│ │
│ ops registry ── each operation: name, │
HTTP API ──▶│ (one table) params struct, inputs, Run() │
│ │ │
│ ├─ chromium (chromedp → headless Chromium,│──▶ chromium-headless-shell
│ │ external requests blocked, PrintToPDF)│ (separate process, reused)
│ ├─ pdfops (pdfcpu: merge, split, ...) │
│ ├─ pdfa (XMP + sRGB output intent ...) │
│ ├─ imgpdf (EXIF orientation, fit, JPEG) │
│ ├─ raster (PDFium-WASM → PNG/WebP/JPEG) │
│ └─ tmpl (Handlebars/Mustache + tr-TR) │
└────────────────────────────────────────────────┘
- One operation table: CLI subcommands and
/v1/<operation>endpoints are generated from the same registry. Parameters are bound from struct tags to CLI flags, form fields, JSON and the OpenAPI schema, so the CLI and the API cannot drift apart. - Stateless: inputs stay in memory, and Chromium receives documents straight from memory, never from disk. Async job results are kept in memory with a TTL.
- Security: external network requests are blocked by default, the container runs as a non-root user with a read-only root, and request size and concurrency are limited.
Notes on fonts and PDF/A
- The standard 14 PDF fonts cannot encode Turkish letters such as ş, ğ, ı and İ, so text watermarks need an embedded TrueType font. Chromium embeds variable fonts as Type3 glyphs, so pidief ships static font instances.
- Chromium header/footer templates cannot load web fonts, so the Docker image installs Onest as a system font.
- Chromium does not produce PDF/A by itself; pidief adds XMP metadata, an output intent and annotation flags afterwards.