Pivot PDF
A PDF creation library written in Rust, designed to be used from any language. The core is implemented in Rust and can be used directly in Rust projects. Language bindings are being built for PHP, Java, C#, Python, Go, and other major languages.
Designed for low memory and CPU consumption — even for documents with hundreds of pages — making it well suited for SaaS and web applications that generate reports, contracts, invoices, or bills of material on the fly.
Features
- Text placement — place text at arbitrary (x, y) positions using any supported font
- TextFlow — automatic word wrap and multi-page text reflow with mixed font styles
- 14 built-in fonts — all standard PDF fonts (Helvetica, Times, Courier, Symbol, ZapfDingbats) with no embedding required
- TrueType font embedding — load
.ttffiles for full Unicode text with automatic metrics extraction - Line graphics — move/lineto paths, rectangles, stroke, fill, fill-stroke, color and line-width control
- Images — place JPEG and PNG images (with alpha) using fit, fill, stretch, or none fit modes
- Tables — streaming row-by-row table layout with per-cell styles, overflow modes, borders, and background colors
- Page editing — open completed pages for overlay content (e.g. "Page X of Y" numbering)
- Compression — optional FlateDecode compression for all stream objects (typically 50–80% size reduction)
- PHP extension — full PHP binding exposing all features via a native extension
PHP Installation
Install the Composer package for IDE autocompletion stubs:
The native extension binary must be installed separately. For the full installation guide, see docs/php-installation.md.
Requirements
Rust (pdf-core, pdf-cli)
- Rust stable toolchain — install via rustup
PHP Extension (pdf-php)
- Rust stable toolchain (same as above)
- PHP development headers:
sudo apt install php-dev - Clang development libraries:
sudo apt install libclang-dev
Building
# Build all workspace members (debug)
# Build release (recommended for PHP extension)
Running Tests
# Run all Rust tests
Rust Examples
Examples write output PDFs to the examples/output/ directory.
# Basic document — place_text
# TextFlow — multi-page text reflow with mixed font styles
# Line graphics — paths, rectangles, stroke, fill
# Images — JPEG and PNG placement
# Tables — streaming row layout with headers
# TrueType fonts — embed a .ttf font
# Page numbers — edit completed pages to add "Page X of Y"
PHP Extension
Build
The compiled extension is at target/release/libpdf_php.so.
Run Tests
Run PHP Examples
Each PHP example mirrors its Rust counterpart and writes to the examples/output/ directory.
EXT="-d extension=target/release/libpdf_php.so"
IDE type hints and autocompletion are provided by pdf-php/pdf-php.stubs.php.
Workspace Structure
pivot-pdf/
├── pdf-core/ # Core library — all PDF generation logic
│ ├── src/
│ └── tests/
├── pdf-php/ # PHP extension wrapping pdf-core
│ ├── src/
│ └── tests/
├── examples/ # Rust and PHP example programs
│ ├── rust/
│ ├── php/
│ └── output/ # Generated PDFs (git-ignored)
└── docs/ # Architecture and feature documentation
Coordinate System
All coordinates are in PDF points (1 pt = 1/72 inch) with the origin at the bottom-left of the page. A standard US Letter page is 612 × 792 pt.