Document Generation Engine: Real PDFs and PowerPoint Files from Structured Data
The Ark Document Engine produces two kinds of real, downloadable documents from structured JSON: PDFs and PowerPoint presentations. PDFs render through a self-hosted Typst engine against six production templates — market report, proposal, project update, invoice, competitive report, and plan export — while slide decks render in pure Rust to genuine OOXML .pptx files that open in PowerPoint, Keynote, or LibreOffice. Both paths were verified to emit real binaries, not placeholders: a market-report request returned a valid 3-page %PDF-1.7 (39 KB), a raw-Typst request returned a 1-page PDF (16.7 KB), and a slides request returned a real Microsoft PowerPoint 2007+ file (13 KB) with the correct OOXML magic bytes — all reproduced over the public Cloudflare route on first attempt. Because the slide engine is pure Rust (no Node, no headless browser), the whole service ships as a single binary. Output is deterministic — identical input yields byte-identical output — and every document emits production telemetry (size, generation time), with templated PDFs rendering in under ~200ms. The engine is functionally complete; the honest gap before it can be sold is access control: the public generate route currently has no auth, so a JWT gate and usage metering are the remaining step before monetization.
Key Metrics
PDF output
Before
Headless-browser HTML-to-PDF — heavy, slow, browser runtime in every deploy
After
Self-hosted Typst renders real %PDF-1.7 (verified 39 KB/3-page and 16.7 KB/1-page) in under ~200ms for templates, no browser
PowerPoint output
Before
SaaS calls, LibreOffice shell-outs, or fake .pptx files
After
Pure-Rust OOXML — verified real Microsoft PowerPoint 2007+ .pptx (13 KB) that opens in PowerPoint/Keynote/LibreOffice
Deployment footprint
Before
Node runtime and/or headless browser required
After
Binary-only deploy — pure-Rust slide rendering means no Node, no browser
Reproducibility
Before
Non-deterministic output that breaks caching
After
Deterministic — identical input yields byte-identical output, verified local vs Cloudflare
Watch the Walkthrough
The Challenge
Generating professional documents programmatically is a minefield of bad options. Server-side PDF generation is dominated by headless-browser approaches (spin up Chrome, render HTML, print to PDF) that are heavy, slow, fragile, and drag a whole browser runtime into every deployment. PowerPoint generation is worse — most solutions either call a third-party SaaS, shell out to LibreOffice, or emit a fake .pptx that is really an image or an HTML file with the wrong extension. Neither fits a binary-only, self-hosted deployment, and neither is deterministic: run the same request twice and you can get subtly different bytes, which breaks caching and reproducibility. The requirement is a document engine that renders real, standards-compliant PDFs and genuine OOXML PowerPoint files from structured data, in-process, with no browser and no third-party service, deterministically, fast enough to serve inline.
Why This Approach?
PDF rendering engine
Self-hosted Typst binary with templated documents
Typst renders high-quality typeset PDFs from a compact markup without a browser runtime — templated PDFs come back in under ~200ms. It ships as a self-hosted binary with no external service in the path, unlike headless-browser or SaaS approaches that add weight, latency, and a third-party dependency.
Alternatives considered: Headless-Chrome HTML-to-PDF, wkhtmltopdf, a PDF SaaS
PowerPoint rendering
Pure-Rust OOXML generation (pptrs-fallback, default-on)
Rendering .pptx in pure Rust means genuine OOXML output with no Node runtime, no headless browser, and no external service — so the whole engine ships in a single binary-only deploy. The verified output is a real Microsoft PowerPoint 2007+ file, not an image or HTML fake.
Alternatives considered: Headless-browser export, LibreOffice conversion, a third-party slides API
Output determinism
Deterministic rendering — identical input yields byte-identical output
Byte-identical output for identical input makes results cacheable and reproducible — verified when a raw-Typst render reproduced the same PDF locally and over the Cloudflare route. Non-deterministic output would break caching and make verification impossible.
Alternatives considered: Timestamped/randomized output, non-reproducible layout passes
Build Process
Templated PDF generation
POST /api/pdf/generate renders one of six production Typst templates — market-report, proposal, project-update, invoice, competitive-report, plan-export — from structured data. Verified: a market-report request returned a valid 3-page %PDF-1.7 (39 KB), with templated PDFs rendering in under ~200ms.
Raw-Typst engine isolation
POST /api/pdf/from-typst renders arbitrary Typst source directly, isolating the engine from the template layer. Verified: a raw source request returned a 1-page %PDF-1.7 (16.7 KB), and the render was deterministic — the same input reproduced byte-for-byte locally and over the public route.
Native PowerPoint generation
POST /api/slides/generate renders structured report data into a genuine OOXML .pptx in pure Rust — no Node, no headless browser. Verified: the response carried the PowerPoint 2007+ MIME type and PK.. magic bytes (a real 13 KB .pptx that opens in PowerPoint, Keynote, and LibreOffice).
Live delivery, determinism, and telemetry
All three paths were verified over the public Cloudflare route (docgen.chakrakali.com) on first attempt, with /health returning 200. The engine ships binary-only, emits production telemetry on every document (file size, generation time, success/error), and produces deterministic output. A richer surface exists beyond the core jobs: PDF preview and compose (LLM data synthesis), slides design (prompt-to-PPTX), pitch-deck generation, board updates, and PDF/HTML export.
Challenges & Solutions
Impact
Spinning up Chrome to render HTML-to-PDF is heavy, slow, and drags a browser runtime into every deployment.
Solution
A self-hosted Typst engine that renders typeset PDFs from compact markup in-process, with no browser.
Result
Verified real %PDF-1.7 output (39 KB / 3 pages templated, 16.7 KB / 1 page raw) with templated PDFs under ~200ms — no browser in the path.
How AI Powers This
AI Capability
Templated PDF Rendering (Typst)
Generate professional PDFs — market reports, proposals, invoices, project updates — from structured data, fast, with no browser or third-party service
Business outcome
Verified real 3-page %PDF-1.7 (39 KB) from a market-report request over the live route
Under the hood
POST /api/pdf/generate {template, theme, data} -> self-hosted Typst binary renders one of 6 templates -> %PDF-1.7 binary response, under ~200ms for templates
How success is measured: PDF validity (magic bytes, page count), render latency, template fidelity to the data
AI Capability
Native PowerPoint Generation
Produce genuine, editable PowerPoint decks from report data — files that open cleanly in PowerPoint, Keynote, and LibreOffice
Business outcome
Verified real Microsoft PowerPoint 2007+ .pptx (13 KB) in a binary-only deploy
Under the hood
POST /api/slides/generate {report} -> pure-Rust OOXML rendering (pptrs-fallback) -> valid .pptx (application/vnd...presentationml.presentation), no Node/headless browser
How success is measured: OOXML validity (PK.. magic, PowerPoint-openability), fidelity of the deck to the report data
AI Capability
LLM Data Synthesis & Prompt-to-Document
Go beyond templates — compose documents from a prompt or synthesize the underlying data with an LLM before rendering
Business outcome
Adds a generative path on top of the deterministic template engine — prompt or data in, finished document out
Under the hood
/api/pdf/compose (LLM data synthesis) and /api/slides/design (universal prompt -> PPTX) sit alongside the deterministic template renderers
How success is measured: Synthesis relevance, rendered-document quality, alignment with the requested structure
AI Capability
Deterministic, Observable Rendering
Identical requests produce identical files — results are cacheable and reproducible — and every document is measured for size and speed
Business outcome
Verified byte-identical raw-Typst output across local and Cloudflare routes, with production observability on every render
Under the hood
deterministic Typst/OOXML rendering; production telemetry emitted per document (document_requested/generated/error with file_size_bytes, generation_ms)
How success is measured: Byte-for-byte reproducibility, telemetry completeness
Results & Metrics
PDF output
ImprovedBefore
Headless-browser HTML-to-PDF — heavy, slow, browser runtime in every deploy
After
Self-hosted Typst renders real %PDF-1.7 (verified 39 KB/3-page and 16.7 KB/1-page) in under ~200ms for templates, no browser
PowerPoint output
ImprovedBefore
SaaS calls, LibreOffice shell-outs, or fake .pptx files
After
Pure-Rust OOXML — verified real Microsoft PowerPoint 2007+ .pptx (13 KB) that opens in PowerPoint/Keynote/LibreOffice
Deployment footprint
ImprovedBefore
Node runtime and/or headless browser required
After
Binary-only deploy — pure-Rust slide rendering means no Node, no browser
Reproducibility
ImprovedBefore
Non-deterministic output that breaks caching
After
Deterministic — identical input yields byte-identical output, verified local vs Cloudflare
Sellability gap (honest)
ImprovedBefore
N/A
After
Functionally complete but the public generate route has NO auth — a JWT gate + usage metering are the remaining step before monetization
System Overview
The architecture below is the technical foundation behind every business outcome on this page — built for reliability, low running cost, and the speed your customers feel.
A Rust document engine (ark-docgen, :3800) exposing two core generation paths. PDFs render through a self-hosted Typst binary against six production templates (market-report, proposal, project-update, invoice, competitive-report, plan-export) via /api/pdf/generate, plus a raw-Typst path (/api/pdf/from-typst) that isolates the engine. Slides render in pure Rust to genuine OOXML .pptx via /api/slides/generate (pptrs-fallback default-on) — no Node, no headless browser — so the whole service ships binary-only. Output is deterministic (identical input yields byte-identical output) and every document emits production telemetry (file size, generation time, success/error). Templated PDFs render in under ~200ms. A wider surface includes /api/pdf/preview, /api/pdf/compose (LLM data synthesis), /api/slides/design (prompt-to-PPTX), /api/slides/generate/pitch-deck, /board-update, and PDF/HTML export. Verified live over the public Cloudflare route. CAVEAT: the public generate route currently has no auth — a JWT gate and usage metering are required before monetization. Note also that the market-report template's data schema differs from the slides MarketReport shape (its executive_summary is an object), so per-template schemas must be documented before public exposure.Technologies Used
Rust, Typst (PDF), pure-Rust OOXML PPTX (pptrs-fallback), deterministic rendering, production telemetry, binary-only deploy