Installation
forme-pdf on crates.io. The library name is forme:
Quick start
API
| Function | Description |
|---|---|
render(&Document) | Render a Document struct to PDF bytes |
render_json(&str) | Parse JSON and render to PDF |
render_with_layout(&Document) | Render and return layout metadata |
render_json_with_layout(&str) | Parse JSON, render, and return layout metadata |
render_template(&str, &str) | Evaluate a template with data, then render |
render_template_with_layout(&str, &str) | Evaluate a template with data, render, and return layout metadata |
Result<Vec<u8>, FormeError> (or Result<(Vec<u8>, LayoutInfo), FormeError> for the _with_layout variants).
Working with the Document struct
For full control, build aDocument directly instead of using JSON:
Templates
Render dynamic documents by combining a template (with$ref, $each, $if expressions) and a data object:
Layout metadata
The_with_layout variants return a LayoutInfo struct describing the position and dimensions of every element on every page. Useful for overlays, click-to-inspect, and testing:
Features
The engine supports:- Flexbox layout — row, column, wrap, grow/shrink, all alignment modes
- CSS Grid — track sizing, auto/explicit placement,
repeat()syntax - Text — OpenType shaping, Knuth-Plass line breaking, hyphenation (35+ languages), BiDi, per-character font fallback
- Tables — automatic header repetition on page breaks
- Images — JPEG, PNG, WebP
- SVG — inline rendering (rect, circle, line, path, arc)
- Charts — BarChart, LineChart, PieChart, AreaChart, DotPlot
- QR codes & barcodes — Code128, Code39, EAN13, EAN8, Codabar
- Tagged PDF / PDF/A-2a — accessibility and archival compliance
- Embedded data — attach JSON inside the PDF for round-tripping
WASM
The crate compiles to WebAssembly. Enable thewasm feature for wasm-bindgen support:
@formepdf/core works under the hood — the same engine, compiled to WASM and called from JavaScript.