A high-level, ergonomic Rust library for creating PDF documents.
open sourceMIT OR Apache-2.0self-hostablefree
krilla is a Rust crate for creating PDF files from high-level drawing primitives: fills, strokes, gradients, masks, clip paths, blend modes, glyphs and images. It's built on pdf-writer and handles fonts itself, with OpenType and colour font support, a simple text API that shapes text with HarfRust, and font subsetting with the subsetter crate. It also writes outlines, page labels, links and annotations, metadata and tagged PDF, targets PDF 1.4 to 2.0, and can export to validated PDF/A-1 to PDF/A-4 and PDF/UA-1. It's meant for libraries that already have laid-out content (from HTML or their own layout engine), and is tested against snapshot tests, veraPDF and six PDF viewers; krilla-svg converts SVG to PDF.
Problems it solves
- turn my Rust layout engine's output into a PDF without writing raw PDF objects
- draw paths, gradients and images onto PDF pages from Rust with a 2D graphics style API
- export PDF/A or PDF/UA compliant files from a Rust application
- generate tagged, accessible PDFs from Rust
- put text in any OpenType font, including colour emoji fonts, into a PDF and have it subset automatically
- convert SVG graphics to vector PDF content in Rust
- make PDF generation faster with multithreaded compression of pages and images
- add bookmarks, page labels and links to PDFs generated in Rust
- a PDF backend that renders the same way in Acrobat, Chrome, Preview and other viewers
- embed pages from an existing PDF into a new one I'm drawing in Rust
Features
- fills, strokes, affine transforms, alpha and luminosity masks, clip paths and blend modes
- high-level text API (shaping with HarfRust) and a low-level positioned-glyph API
- OpenType fonts of all major flavours, including colour fonts
- font subsetting for CFF and TrueType fonts
- linear, radial and sweep gradients and patterns
- bitmap images (PNG, JPEG, GIF, WebP) and SVG via krilla-svg
- outlines, page labels, annotations, links and named destinations, metadata
- tagged PDF for accessibility
- PDF versions 1.4 to 2.0 and validated PDF/A-1 to PDF/A-4 and PDF/UA-1 export
- embedding pages from other PDF documents (pdf feature)
View 2 more
- optional multithreading with rayon
- snapshot, veraPDF and multi-viewer visual regression tests; no unsafe code
Limitations
- Doesn't lay out text, build tables, break pages or add headers and footers: it draws content you have already laid out1
- Doesn't encrypt PDFs or add digital signatures: out of scope for now, like many other PDF features1
Capabilities
| Has official SDKs | plan not known |
|---|
Alternatives
The same job
These do what krilla does.
- pdf-writer A step-by-step PDF writer.
- Typst The new foundation for documents
- ironpress HTML to PDF. In process. In pure Rust.
