Preview Self-hosted PDF generation

Compile your PDF layout once. Generate it offline.

ForkPDF AOT turns an observed HTML/CSS layout into a self-hosted .fpaot bundle. Generate PDFs offline in Node or a Worker with selectable compliance profiles — no Chromium, no browser, and no ForkPDF API in the request path.

The example below uses a compiled invoice bundle. Unsupported layouts fail closed.
No browser Generate in Node, Workers, or serverless
No API call The compiled bundle is the generation runtime
Selectable compliance Plain · PDF/UA-1/2 · PDF/A-2/3/4 · locked per bundle
Fail closed Unknown layouts can fall back to the Cloud API

One page. Two pages. From the same bundle.

These are PDFs generated by the benchmark Worker and converted to preview images.

1 page · 5 items
Generated one-page invoice with five line items Page 1 · items 1–5
Single-page invoice One-line project and notes. PDF/UA-2 + PDF/A-4 validated.
2 pages · 18 items
First page of an eighteen-item invoice generated by the Worker Page 1 · items 1–11
Second page of an eighteen-item invoice with brought-forward total, totals and payment block Page 2 · items 12–18
Two-page invoice Carried-forward and brought-forward rows, totals, and payment block.

API reference vs AOT output.

Same payload. The left side is the original API render. The right side is the structurally generated AOT PDF.

Five-item invoice rendered by the ForkPDF API
Five-item invoice structurally generated by the AOT bundle
API render AOT bundle

Drag the divider to reveal each version. Both sides use the same five-item payload.

What this example bundle covers.

This preview bundle was compiled from every combination of 18 item counts, project descriptions at one or two lines, and notes at one or two lines. Every item description and detail stays on one line.

1p one page 2p two pages

Page count for 18 item counts across four project and notes line profiles
Profile 123456 789101112 131415161718
P1 / N11p1p1p1p1p1p1p2p2p2p2p2p2p2p2p2p2p2p
P1 / N21p1p1p1p1p1p1p2p2p2p2p2p2p2p2p2p2p2p
P2 / N11p1p1p1p1p1p1p2p2p2p2p2p2p2p2p2p2p2p
P2 / N21p1p1p1p1p1p1p2p2p2p2p2p2p2p2p2p2p2p
72payloads
72plans
268plates
7.7 MBbundle
72 / 72payload validation
5 / 5Worker PDFs compliant

Declared envelope, validated across all 72 shapes. This is the invoice example, not a universal coverage claim. Certificates, payslips, tickets, and badges often have smaller finite variant sets, so they can be compiled exhaustively and covered 100% within their declared envelope.

Cloudflare Workers benchmark

Workers Paid, Delhi (DEL), 20 warm-up requests and 100 measured warm requests per shape.

260–425 ms warm PDF-ready p50
full PDF delivery p50 2.8–3.3 MB example files
1.95 s cold request p50
DEL measured colo

These PDF sizes are for the example bundle compiled with PDF/UA-2 + PDF/A-4. AOT also supports plain output, PDF/UA-1/2, PDF/A-2/3/4, and combined profiles. The selected profile is locked per bundle, and these sizes are not a minimum or universal AOT output size.

ShapeWarm PDF-ready p50Warm PDF-ready p95Full PDF p50PDF size (UA-2 + A-4)
1 page · 5 items269 ms414 ms383 ms2.82 MB
1 page · 7 items260 ms447 ms356 ms2.82 MB
2 pages · 12 items378 ms603 ms493 ms3.26 MB
2 pages · 18 items425 ms664 ms547 ms3.26 MB

Cold isolate

1.95 s TTFB p50 across 10 fresh versions. Every sample reported a cold runtime cache. Bundle load was ~19 ms because the asset was already cached in the colo.

First request after deploy

3.8 s total, including a 1.76 s bundle asset pull and the first-generation lazy plan/plate load.

“PDF-ready” is time to response headers and includes network latency plus generation. Full-PDF time includes transferring the entire file. These numbers are from one colo, not a global guarantee. Workers Paid is required; Free’s 10 ms CPU limit is below this workload.

Coverage is per document family, not universal.

AOT coverage is the share of a declared document set that you enumerate, compile, and validate.

Exhaustive AOT

Closed, limited variant sets

  • Certificates and awards
  • Payslips and earnings statements
  • Tickets, passes, and event badges
  • Fixed-format labels and cards

Compile every variant and AOT can cover 100% of that declared set with zero API calls at runtime. Unseen variants fail closed so the corpus can be extended.

Measured AOT + API fallback

Variable content, measurable mix

  • Invoices with free-form line items
  • Statements and reports with variable notes
  • Customer-specific document packs

Measure a held-out sample from the customer’s actual document mix. Route the covered share to AOT and send misses to the Cloud API.

Not a fit

Unbounded or user-authored layouts

  • Arbitrary HTML-to-PDF
  • User-authored templates
  • Unbounded tables or page designs

Use the Cloud API when the layout itself changes at runtime or the variation set cannot be enumerated.

A “90%” result is only meaningful as 90% of this customer’s measured document mix, not “90% of all invoices.” A closed certificate or badge program can instead be compiled exhaustively and reach 100% of its declared set.

Three steps. One compiled file.

You keep using the same HTML, CSS, and layout-check script. AOT changes when and where the PDF is generated.

1

Observe layouts

Render the template across its supported data shapes and capture the pages, text slots, and pagination decisions.

2

Compile

Run fpaot compile. ForkPDF turns those observations into one .fpaot bundle.

Compile runs on your build machine. Plate generation is self-contained: bundled PDF.js and @napi-rs/canvas, with no Inkscape, Poppler, or system fonts required.

3

Generate offline

Load the bundle in Node or a Worker. No Chromium, no browser, and no ForkPDF API request at generation time.

What gets compiled?

ForkPDF keeps observed pages, plates, glyphs, line-break rules, and the template testcase. It does not ship Chromium or call the API at runtime.

For the compiler internals, read Inside the .fpaot Compiler.

Your templateHTML · CSS · layout-check script
→
Observe layoutssupported data shapes
→
Compileone .fpaot bundle
→
Generate offlineNode · Worker · serverless
Use it in Node
import fs from 'node:fs';
import { loadCompiled } from 'forkpdf-aot/runtime';

const runtime = loadCompiled('template.fpaot');
const result = await runtime.generate(documentData, {
  includePb: false
});

if (!result.ok) {
  throw new Error(result.code);
}
fs.writeFileSync('invoice.pdf', result.pdf);
Use it in a Worker
import { loadCompiledBytes } from 'forkpdf-aot/worker';

const runtime = loadCompiledBytes(
  await env.AOT_BUNDLE.arrayBuffer()
);
const result = await runtime.generate(documentData, {
  includePb: false
});

if (!result.ok) {
  return Response.json({ code: result.code }, { status: 422 });
}
return new Response(result.pdf, {
  headers: { 'content-type': 'application/pdf' }
});

includePb: false skips the spatial data.pb payload when you only need the PDF bytes.

Supported envelope and preview status.

If the data needs a layout that was never observed, AOT fails closed so the caller can send it to the Cloud API.

Works offline

  • 1–18 line items
  • One-line item descriptions and details
  • Project descriptions and notes at 1 or 2 lines
  • Changed client name, invoice number/dates, item text, rates, amounts, and totals
  • One-page and two-page invoice layouts
  • Selectable compliance profiles locked per bundle; the example uses PDF/UA-2 + PDF/A-4

Falls back to the Cloud API

  • 19 or more line items
  • Item details that need a second line
  • Project descriptions or notes that need 3+ lines
  • Unobserved layouts
  • Arbitrary HTML-to-PDF at runtime
  • Workers Free, because the 10 ms CPU limit is too small

Preview status

  • APIs and bundle format may change before 1.0.0
  • A held-out benchmark across general invoice workloads is not yet complete
  • Compile requires Node.js 22.13+ on the build machine; runtime generation supports Node.js 18+ and Workers. Inkscape, Poppler, and system fonts are not required.

Fail-closed codes are stable enough to route programmatically: E_MISSING_PLAN for an unobserved item count and E_CONTENT_PROFILE_NOT_FOUND when text needs a taller line profile.

Designed to be checked, not trusted.

The preview bundle is validated against the rendered corpus and the generated structural output. The Worker benchmark also downloads real PDFs and checks them with veraPDF, so the numbers and compliance claim come from the deployed path rather than a local lookup.

Invoice AOT verification checks
Corpus payloads generated72 / 72
Compiled plans72
Required plates available268 / 268
Changed core invoice fields3 / 3 shapes
Worker PDFs passing PDF/UA-2 + PDF/A-45 / 5
ForkPDF API calls during Worker generation0
Unsupported 19-item payload422 refused

Terms on this page

No prior ForkPDF knowledge required.

.fpaot
A single compiled bundle containing the observed pages, plates, glyphs, and layout rules needed to generate PDFs later.
Plate
A pre-rendered page fragment containing background graphics and text/image slots that the runtime reuses to rebuild an observed page.
Observed layout
A data shape ForkPDF rendered while building the corpus, including item count, line profiles, and page split.
Testcase
Compiled, sandboxed template code that can measure layout, decide pagination, compute values, and apply a final page plan.
data.pb
The spatial layout data that records where text, images, and rows appeared on the page.
Changed input
Different invoice text or values that stay inside an observed line profile. ForkPDF rebuilds the PDF structurally.
Fail closed
If a required layout was never observed, ForkPDF returns a clear error instead of guessing or selecting a nearby layout.

What changed in this preview

New

  • Self-contained plate compilation with bundled PDF.js and @napi-rs/canvas — no Inkscape, Poppler, or system fonts
  • Selectable compliance: plain, PDF/UA-1/2, PDF/A-2/3/4, and combined profiles, locked per bundle
  • 72-shape invoice example corpus with 1–18 one-line item rows
  • One-page and two-page structural generation
  • Cloudflare Workers benchmark with real PDF downloads

Fixed

  • Single-token text, fixed table cells, and no-wrap totals remain reflowable
  • PDF 2.0 header preserved after trailing blank-page trimming
  • Unknown layouts fail closed instead of selecting a nearby plan

Frequently asked questions.

The short version of how AOT works, what it supports, and where it runs.

What is ForkPDF AOT?

ForkPDF AOT compiles observed HTML/CSS layouts into one .fpaot bundle. You can later generate PDFs from that bundle without Chromium, a browser, or a ForkPDF API request.

Does AOT only support PDF/UA-2 + PDF/A-4?

No. PDF/UA-2 + PDF/A-4 is the profile used by the invoice example. The compiler supports plain output, PDF/UA-1/2, PDF/A-2/3/4, and combined profiles. The selected profile is locked to the bundle, so runtime requests cannot silently downgrade or switch policy.

Which invoice layouts are supported?

The preview bundle covers 1–18 invoice items, one-line item descriptions and details, and project descriptions and notes at one or two lines. It generates one-page and two-page layouts. Unsupported layouts fail closed so the caller can use the Cloud API.

Can AOT cover 100% of a document type?

Yes, for a closed variant set that you enumerate and compile. AOT can cover 100% of the declared variants with no API calls at runtime. For open-ended document families, measure coverage against a held-out customer sample and route misses to the Cloud API. There is no universal coverage percentage.

Which Cloudflare plan is required?

Workers Paid is required. Structural generation uses roughly 150–315 ms CPU when warm and about 1.6–1.9 seconds CPU on a cold request, well above the Free plan’s 10 ms CPU limit.

Is ForkPDF AOT stable?

No. AOT is a preview feature. The package, bundle format, and APIs may change before the first stable 1.0.0 release.

Preview

Start with a compiled bundle.

Inspect the invoice example and edge numbers, then compile your own template and declare its supported envelope.

npm install forkpdf-aot@preview npm install --save-dev forkpdf-aot-compiler@preview