Create invoices, receipts, reports, and templated documents from data. Pure Rust, no Java, no Python, no native dependencies.
use pdfluent::{Document, Page, Font, Color};
fn generate_invoice(order: &Order) -> Vec<u8> {
let mut doc = Document::new();
let mut page = Page::a4();
// Title
page.add_text(
&format!("Invoice #{}", order.id),
Font::helvetica_bold(24),
Position::new(50.0, 780.0),
);
// Line items table
let mut y = 700.0;
for item in &order.items {
page.add_text(
&item.description,
Font::helvetica(11),
Position::new(50.0, y),
);
page.add_text(
&format!("€ {:.2}", item.price),
Font::helvetica(11),
Position::new(480.0, y),
);
y -= 20.0;
}
// Footer
page.add_text(
&format!("Total: € {:.2}", order.total),
Font::helvetica_bold(13),
Position::new(50.0, y - 20.0),
);
doc.add_page(page);
doc.save_bytes()
}Run cargo add pdfluent to get started.
Produce invoices, receipts, delivery notes, and reports directly from your application data. Pass a struct or JSON value; PDFluent lays out the document. No intermediate HTML, no headless browser, no external service call.
Define reusable page templates with fixed layout regions — headers, footers, columns, tables — and fill them with dynamic content at runtime. Templates are plain Rust structs, versioned alongside your code.
PDFluent is a pure Rust crate with no C FFI, no Java, and no Python runtime. It compiles on Linux, macOS, Windows, and to wasm32-unknown-unknown. Deploy to AWS Lambda, Cloudflare Workers, or any container without extra system packages.
Embed TTF and OTF fonts, control kerning, line height, and text wrapping. Supports Unicode including RTL scripts. Subset fonts to keep file sizes small.
Build structured tables with column alignment, cell borders, background colors, and automatic row pagination. Tables that overflow a page are split across pages automatically.
Embed PNG, JPEG, and WebP images. Draw lines, rectangles, and paths for borders, dividers, and charts. All coordinates use the PDF user-space coordinate system.