| Crates.io | fpdf |
| lib.rs | fpdf |
| version | 0.1.1 |
| created_at | 2025-09-02 17:58:00.259095+00 |
| updated_at | 2025-10-02 12:42:01.685876+00 |
| description | FDPF for writing PDF files in Rust. |
| homepage | |
| repository | https://codeberg.org/maik-steiger/fpdf-rs |
| max_upload_size | |
| id | 1821479 |
| size | 3,822,576 |
A PDF document generator with high level support for text, drawing and images. It is written in safe Rust.
[!IMPORTANT] This project is in its very early development state and is thus prone to API changes. It is not recommended to build a product around this crate for the time being.
If you encounter any issue or crashes using this crate, please open an issue and post a reproducible setup.
If you have any wishes as to how the API can be improved and be made more "Rust"-idiomatic, please open an issue with that request.
The fpdf crate has its use of dependencies minimized. This avoids
compilation bloat for any project and its target binary size and
performance is more predictable.
fpdf explicitly supports UTF-8 TrueType fonts and "right-to-left"
languages.
Additional Features:
To use fpdf in your Rust project, just run the following command in your project directory:
$ cargo add fpdf
Here is an example code shown for a very quick introduction into the
FPDF API. Take a look at the examples/ folder for more examples.
use fpdf::{Fpdf, Pdf, Unit};
fn main() {
// Create a new Fpdf object instance
let mut pdf = Fpdf::default();
// Set the font to PDF's internal "Arial". Other alternatives would be:
// "Helvetica", "Times", "Symbol" or "Zapfdingbats"
pdf.set_font("Arial", "", Unit::pt(16.0));
// Add a new page to the PDF document (mandatory)
pdf.add_page();
// Print "Hello World!" message in an "imaginary" box of 100mm width
// and 10mm height. Draw no border, align the text to the left "L" and
// don't fill the background
pdf.multi_cell(Unit::mm(100.0), Unit::mm(10.0), "Hello World!", "", "L", false);
// Output the PDF file as "hello_world.pdf" onto the file system
pdf.output_file_and_close("hello_world.pdf").unwrap();
}
The fpdf crate's goal is to become an established, general-use PDF
library, such as the original FPDF for PHP.
The F stands for Free and thus this project is free to use any modify
however you like. A copyleft license is implemented to forbide the
commercial usage of this package for user's in need, like the inspired
Golang FDPF library has
experienced.
If you want finer and more granular control over how your PDF file is produced, consider using one of the alternative Rust crate's for generating PDF files:
To ease the creation of PDF documents, the API mostly panics in case of errors, to avoid unwrap calls in user's code. The error can be read by the user directly to indicate its type. Methods are provided to easily check if the current PDF instance has encountered an error, if the user decides, they want this feature implemented.
The fpdf crate is released under GPLv3 license. It is copyrighted by
Maik Steiger.