mr-pdf 📄✨
mr-pdf is a high-performance, lightweight PDF generation library for Rust. Designed with a focus on low memory footprint and premium aesthetics, it allows you to create stunning PDF documents with a fluent, developer-friendly API.
🚀 Key Features
- Low Memory Footprint: Uses a streaming architecture that writes document sections directly to the output. Memory usage scales with the complexity of a single page, not the entire document.
- Premium Aesthetics: Built-in support for advanced layouts, charts, and modern typography.
- Flexible Layout Engine: Flutter-inspired rows and columns (
Pdf::row,Pdf::column) for complex designs. - Interactive Elements: Support for clickable hyperlinks in text, tables, and images.
- Advanced Tables: Easy-to-use table builder with column spanning, striped rows, and auto-wrapping.
- Rich Media: Support for JPEG, PNG images (file or Base64) and SVG rendering.
- Dynamic Charts: Generate beautiful Bar, Line, and Pie charts directly in your PDF (Optional).
📦 Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
To enable charting capabilities, use the chart feature:
[]
= { = "0.1.0", = ["chart"] }
🛠️ Quick Start
use ;
📊 Visual Components
Beautiful Charts (Opt-in)
Easily visualize data with built-in chart types by enabling the chart feature:
- Bar Charts: For comparison.
- Line Charts: For trends.
- Pie Charts: For proportions.
Flexible Image & SVG Sizing
use SizeExt;
// SVG with custom positioning and size (supports Points or Percent)
pdf.svg
.width
.render?;
// Images (PNG/JPG) with specific position and size
pdf.image
.position
.size
.render?;
Tables with Spanning & Styling
use ;
pdf.table?;
🏎️ Performance Objectives
mr-pdf is tailored for environments where resource efficiency is paramount:
- Direct Writing: Offsets and object metadata are managed centrally, but content streams are flushed directly to the disk/socket once a page is complete.
- Minimal Buffering: Does not store the entire document DOM in memory.
- OptimizedTTF: Only necessary font metrics are loaded into memory for layout calculation.
📄 License
MIT / Apache-2.0