makesPDF
← Back to How to create a PDF

Build and self-host your own

By Jason Galea · Part of the How to create a PDF benchmark

Takeaway: Self-hosting an existing engine trades API bills for container ops, font management and compliance gaps; building your own PDF engine from scratch is a multi-year job once you hit font subsetting, table splitting and PDF/UA tags.

Sample PDFSizePagesTaggedPDF/UA-1PDF/A-2aZürich / 東京 / 🚀Fig altTable tags
chromium-untagged60 KB2nofail (9r / 3765c)fail (5r / 2090c)✓ ✓ ✓✗✗
chromium-tagged126 KB2yesfail (5r / 35c)fail (4r / 2116c)✓ ✓ ✓✓✓

Checked with veraPDF 1.28.2 (r = failed rules, c = failed checks). Click any sample name to download the PDF, or test your own output in /validate (free, no sign-in) and inspect structure trees in /tags.

At some point every engineering team looks at SaaS PDF pricing and asks: "why don't we just run this ourselves?" That splits into two very different projects: self-hosting an existing open-source engine, or building your own renderer.

Option A: Self-hosting an open-source engine

Most teams start by putting headless Chromium (Puppeteer, Playwright or Gotenberg) in Docker. The software licence is free, so the real costs are operational:

  • Memory and concurrency: Each Chromium instance easily eats 200 to 500 MB of RAM. Bursty traffic means writing a pool/queue, bounding concurrency, and chasing zombie processes when a slow page times out.
  • Container weight and patching: You are shipping a 200 MB+ browser binary plus system font packages (fonts-noto-core, fonts-noto-cjk, fonts-noto-color-emoji) and keeping Chromium patched for security advisories.
  • SSRF and untrusted input: Whenever user data reaches an HTML template rendered by a browser inside your VPC, you have to block internal network access (169.254.169.254, localhost, private ranges) or a single <iframe src=...> becomes an SSRF bug.
  • Standards gaps: As the chromium-untagged and chromium-tagged rows above show, default page.pdf() is untagged (3,765 failed PDF/UA-1 checks), tagged: true still fails 5 PDF/UA-1 rules, and Chromium cannot emit PDF/A without bolting on LibreOffice or Ghostscript afterwards.

If you specifically want to self-host and standards compliance matters, you are usually better off running Typst (a single fast binary that passed both PDF/UA-1 and PDF/A-2a in our test) or WeasyPrint (passed PDF/UA-1, no browser) than maintaining a Chromium fleet.

Option B: Building your own PDF engine

I have built variations of a PDF layout engine and writer four times since 2011 (PDF::Boxer, PDF::Grid, Docca, and now makesPDF), so here is the honest inventory of what you are signing up for once you get past "Hello World":

  • Font parsing and CID TrueType subsetting: Embedding full fonts bloats every PDF into megabytes (see the 782 KB jsPDF sample); subsetting means parsing glyph tables, building CID maps and emitting accurate /ToUnicode tables so copy-paste and screen readers work.
  • Per-character font fallback: Splitting text runs at glyph-coverage boundaries so Latin, symbols (✓), CJK (東京) and multi-codepoint colour emoji (🚀, COLR/CPAL tables) can sit in the same sentence without blank boxes.
  • Bidi and line breaking: Reordering right-to-left scripts (Hebrew, Arabic) cleanly across wrapped lines and keeping inline spans and page numbers in the right visual order.
  • Pagination that never fails: Handling blocks, code fences or table rows taller than a single page without infinite pagination loops or clipped text.
  • Tables that split across pages: Repeating header rows cleanly, carrying rowspan cells across page breaks, and keeping column widths aligned.
  • Tagged structure trees (PDF/UA-1): Emitting StructTreeRoot, ParentTree, marked-content IDs (MCID), semantic roles (H1-H6, L/LI/Lbl/LBody, Table/TR/TH/TD, Figure with /Alt, Link), and marking headers, footers and rules as /Artifact.
  • Archival metadata (PDF/A-2a): Valid XMP metadata streams, file IDs, and embedded sRGB ICC output intents so nothing relies on uncalibrated DeviceRGB.
  • Automated compliance testing: Running veraPDF across a real fixture suite in CI on every change so a spacing or font refactor doesn't quietly break accessibility.

None of those pieces is impossible on its own; it's the interactions between them (like a split table row containing RTL text, colour emoji and a page-number placeholder inside a tagged structure tree) that eat months.

Pros and cons

Pros

  • Complete control over layout, determinism, security boundaries and unit cost at very high volume.
  • Zero external vendor dependency; works inside air-gapped or strictly regulated networks.

Cons

  • Real ongoing engineering and ops burden (especially for Chromium fleets).
  • Building a custom engine only pays off if PDF generation is a core part of your product or you have unusual constraints (like fitting a full engine inside a Cloudflare Worker with no browser or filesystem).

When self-hosting is the right call

  • Compliance or data-residency rules forbid sending document payloads outside your own network.
  • You already run high-volume infrastructure and have the engineering time to maintain Typst, WeasyPrint or a hardened Gotenberg/Chromium cluster.

If you just want reliable, compliant PDFs without adopting a browser fleet or writing a font subsetter, look at Typst (for the lightest self-hosted compiler) or makesPDF (for a hosted API).