Shadcn-style components and Tailwind-style utilities, compiled to PDF bytes in memory. Pure Rust — no headless browser, no process spawning, running as a Vercel Function.
One request in, one PDF out. Send a template and its data.
curl -X POST https://pdfcn-rs.vercel.app/api/generate-pdf \
-H "Content-Type: application/json" \
-d '{
"template": "%h1 Invoice\n%p Total: {{ total }}",
"data": { "total": "$42.00" }
}' \
--output invoice.pdf
Edit the template and data, then generate — this calls
/api/generate-pdf on this deployment and renders the PDF
it returns.
Every card below is real engine output from the examples above.
bg-gradient-to-r from-indigo-600 to-fuchsia-500, ring-4 ring-violet-500, outline.
shadow-lg, rounded-2xl, rounded-full pills and circles.
Bold, italic, serif and mono from bundled Inter, Source Serif 4 and JetBrains Mono.
Flex, grid with rows and spans, divide-y, space-x, page breaks.
object-fit and object-position, with the box clipped, also for relative widths.
Bar, line, pie and sparkline charts, QR codes, six barcode symbologies (code128, ean13, ean8, upca, code39, itf), inline SVG.
Factur-X / EN 16931 XML embedded in a PDF/A-style container.
opacity-50, bg-black/50, text-white/80.
rotate-12, scale-75, skew-x-6, translate-y-2, origin-top-left.
text-shadow-md, underline, align-super / align-sub.
Full body accepted by POST /api/generate-pdf. Only template is required.
| Field | Type | Default | Description |
|---|---|---|---|
template | string | — | HAML-like template source (see syntax below). |
data | object | {} | JSON context resolved against {{ ... }} interpolations. |
page.size | "a4" | "letter" | "WxH" | "a4" | Custom sizes take millimeters, e.g. "210x297". |
page.orientation | "portrait" | "landscape" | "portrait" | Page orientation. |
page.margin_mm | number | engine default | Uniform page margin in millimeters. |
filename | string | "document.pdf" | Suggested name via Content-Disposition. |
fonts | object | {} | Map of family name → base64 TTF/OTF bytes. Reference via font-family: "<name>". |
images | object | {} | Map of src key → base64 JPEG/PNG bytes. No network fetch happens at render time — embed bytes yourself. |
theme | object | light | Semantic token set applied before scanning: { "mode": "light" | "dark", "overrides": { "primary": "#2563eb" } }. One entry rebrands every derived utility (bg-primary, text-primary-foreground, …) and every built-in component built on them — no template changes. Malformed themes are a 400. |
svgs | object | {} | Map of id → SVG source text (plain UTF-8, no base64) for %Vector(id="...") placeholders. |
factur_x | object | — | Splices a Factur-X invoice attachment into the response: { "xml": "...", "profile"?: "en16931", "icc_base64"?: "..." }. See the Factur-X section below. |
Responses: 200 with application/pdf bytes on success,
400 for a missing/invalid JSON body, 422 with a plain-text render error: … message
when the template or data is invalid.
Render up to 50 documents per request. All documents share one auth check,
one font/image decode, one deduplicated remote-image fetch pass and — via the parse cache —
one parse of an identical template, while renders fan out across cores. A render failure
inside one document becomes an error entry; its siblings still ship.
curl -X POST https://pdfcn-rs.vercel.app/api/generate-pdf-batch \
-H "Content-Type: application/json" \
-d '{
"theme": { "overrides": { "primary": "#0f766e" } },
"data": { "company": "Acme GmbH" },
"documents": [
{ "template": "%h1 Statement {{ month }}\\n%p {{ company }}",
"data": { "month": "July" }, "filename": "statement-july.pdf" },
{ "template": "%h1 Statement {{ month }}\\n%p {{ company }}",
"data": { "month": "August" }, "filename": "statement-august.pdf" }
]
}'
Shared fields (applied to every document unless it overrides them):
data (per-document keys win, shallow merge), page, theme,
fonts, images, partials, filename.
Per-document fields: template (required), data, page,
filename (defaults to document-N.pdf by position).
{
"results": [
{ "filename": "statement-july.pdf", "pdf_base64": "JVBERi…" },
{ "filename": "statement-august.pdf", "pdf_base64": "JVBERi…" },
{ "filename": "statement-broken.pdf", "error": "render error: …" }
]
}
Problems with the request itself — bad JSON, bad base64,
malformed theme, more than 50 documents — are a 400
before any rendering starts.
| Syntax | Meaning |
|---|---|
%tag | Element, e.g. %h1, %p. Indentation nests children — no closing tags. |
.class-name | A bare div with that class; chain classes like .flex.gap-2 (Tailwind-style utilities). |
%tag.class(attr="value") | Tag plus classes plus attributes in parentheses. |
{{ path.to.value }} | Interpolates from data; also valid inside attribute values. |
- if cond / - else | Conditional branch on a truthy value from data. |
- for x in list | Repeats the indented block once per item, binding x. |
- include "name" | Inlines a caller-supplied partial (requires a Partials resolver on the embedding side; the HTTP API uses NoPartials). |
Shadcn-style, pre-styled, used the same way as any %tag:
DocumentLayout Header Card Table Grid
Badge Separator SignatureBlock InvoiceTable
Alert Avatar Input Textarea Select
Label Checkbox RadioItem Progress
Breadcrumb Pagination BarChart QRCode
PageFooter LineChart StackedBarChart PieChart
Sparkline Barcode Vector a (links)
A plain %a(href="…") becomes a real, clickable PDF link annotation.
See the "Links" example above.
href | What happens in the PDF |
|---|---|
https://… / http://… | Opens the URL. |
mailto:… / tel:… | Opens the mail or phone app. |
#section | Jumps to the element with id="section" (%h2#section), on whichever page it lands. |
| anything else | Left as plain text: javascript:, relative paths and unknown ids never become links. |
A link that wraps onto several lines gets one clickable area per line; a
link that should cover a whole card needs display:block (class block). Links inside a
CSS-transformed element are not repositioned. Text and inline elements on neighbouring template lines are separated
by a space, as in HAML.
Generated natively at render time — no network, no uploaded images. Try the "Codes" example above, or copy a line below.
| Component | scheme | Accepts |
|---|---|---|
%QRCode(value="https://…" size="120px") | QR | Any text up to ~1 KB: URLs, payment links, WIFI:…, vCards. |
%Barcode(scheme="…" value="…" w="220px" h="56px") | code128 (default) | Any printable ASCII; digit runs switch to dense mode automatically. |
ean13 | 12 digits (check digit added) or 13 (validated). | |
ean8 | 7 or 8 digits. | |
upca | 11 or 12 digits. | |
code39 | A-Z 0-9 - . space $ / + % (lowercase is upper-cased). | |
itf | Digits only (interleaved 2 of 5); an odd count gets a leading zero. |
An invalid value (bad check digit, unsupported character) renders an explicit marker in the PDF instead of a barcode that would scan wrong.
Splices an EN 16931/CII invoice XML into the response as a Factur-X-compliant
attachment, via an extra top-level factur_x field. Try the "Factur-X invoice"
example above — the PDF it returns actually carries the attachment; a page-view can't show it, but
pdftk in.pdf dump_data or any PDF/A-3-aware viewer's attachments panel will.
| Field | Type | Default | Description |
|---|---|---|---|
factur_x.xml | string | — | EN 16931/CII invoice XML, plain UTF-8 (required if factur_x is present). |
factur_x.profile | string | "en16931" | minimum, basic-wl, basic, en16931, or extended. |
factur_x.icc_base64 | string | — | A genuine sRGB ICC profile, base64-encoded, embedded as the PDF/A /OutputIntent. Omitted rather than fabricated when absent — see docs/spikes/002-factur-x-embedding.md. |