#pdf #text #layout


User-friendly PDF generator written in pure Rust

1 unstable release

0.4.0 Dec 14, 2022

#619 in Text processing

Download history 92/week @ 2022-12-11 192/week @ 2022-12-18 12/week @ 2022-12-25 62/week @ 2023-01-01 13/week @ 2023-01-08 35/week @ 2023-01-15 21/week @ 2023-01-22 153/week @ 2023-01-29 97/week @ 2023-02-05 135/week @ 2023-02-12 56/week @ 2023-02-19 27/week @ 2023-02-26 14/week @ 2023-03-05 19/week @ 2023-03-12

117 downloads per month


3.5K SLoC


This is a fork of genpdf-rs by RCKIVE.

A user-friendly PDF generator written in pure Rust.


genpdf is a high-level PDF generator built on top of printpdf and rusttype. It takes care of the page layout and text alignment and renders a document tree into a PDF document. All of its dependencies are written in Rust, so you don’t need any pre-installed libraries or tools.

// Load a font from the file system
let font_family = genpdf::fonts::from_files("./fonts", "LiberationSans", None)
    .expect("Failed to load font family");
// Create a document and set the default font family
let mut doc = genpdf::Document::new(font_family);
// Change the default settings
doc.set_title("Demo document");
// Customize the pages
let mut decorator = genpdf::SimplePageDecorator::new();
// Add one or more elements
doc.push(genpdf::elements::Paragraph::new("This is a demo document."));
// Render the document and write it to a file
doc.render_to_file("output.pdf").expect("Failed to write PDF file");

For a complete example with all supported elements, see the [examples/demo.rs][] file.


  • PDF generation in pure Rust
  • Text rendering with support for setting the font family, style and size as well as the text color and text effects (bold or italic) and with kerning
  • Text wrapping at word boundaries and optional hyphenation
  • Layout of elements sequentially or in tables
  • Rudimentary support for shapes
  • Page headers and custom page decorations
  • Embedding images (scale, position, rotate).

Cargo Features

This crate has the following Cargo features (deactivated per default):

  • images: Adds support for embedding images using the image crate.
  • hyphenation: Adds support for hyphenation using the hyphenation crate.


  • printpdf is the low-level PDF library used by genpdf. It provides more control over the generated document, but you have to take care of all details like calculating the width and height of the rendered text, arranging the elements and distributing them on multiple pages.
  • latex generates LaTeX documents from Rust. It requires a LaTex installation to generate the PDF files. Also, escaping user input is a non-trivial problem and not supported by the crate.
  • tectonic is a TeX engine based on XeTeX. It is partly written in C and has some non-Rust dependencies.
  • wkhtmltopdf generates PDF documents from HTML using the wkhtmltox library. It requires a pre-installed library and does not support custom elements.

Minimum Supported Rust Version

This crate supports at least Rust 1.45.0 or later.


Contributions to this project are welcome! Please submit pull requests on Github.

If you are looking for a good starting point, have a look at the issues with the label “good first issue” in genpdf-rs’s issue tracker.


For bug reports or feature requests, please look at the Github Issues board if your issue exists, and create a new one if it doesn't. For questions, check out Github Discussions


This repository is licensed under EUPL-1.2 or later, except for code that is unchanged from the upstream repository as described below.

This code was forked, find the original repository here: https://git.sr.ht/~ireas/genpdf-rs. All code that has not been changed is licensed under Apache-2.0 and MIT, and documentation under CC-0, as described in the original repository README.

As of the time of this writing, no merges have been made from the original repository since its forking. This means that the prime way to find pre-fork code is using Git: git checkout 38dd11e8.


~133K SLoC