Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

printpdf

> 前端框架
Open source

Rust / WASM library for reading, writing and rendering PDF

1.1K stars0 likes1 views
WebsiteGitHub

About

Rust / WASM library for reading, writing and rendering PDF

printpdf

printpdf is a Rust library for creating, reading, writing and rendering PDF documents.

Website | Crates.io | Documentation | Donate

[!NOTE] HTML-to-PDF rendering (PdfDocument::from_html, html feature) works for basic layouts - tables, page breaks, headers/footers - but is still evolving. For pixel-exact control, position PDF elements manually with ops.

Features

  • Pages, Bookmarks, link annotations (read / write)
  • Layers (read / write)
  • Graphics: lines, shapes, bezier curves, SVG content (read / write)
  • Images encoding / decoding (read support: experimental / write supported with image)
  • Embedded fonts, Unicode support (read support: experimental / write)
  • Minifying file size (auto-subsetting fonts)
  • Advanced graphics - overprint, blending, etc.
  • Advanced typography - character / word scaling and spacing, superscript, subscript, etc.
  • Embedding SVGs (uses svg2pdf crate internally)

Experimental features:

  • Rendering PDF pages to SVG (one standalone SVG file per page)
    • You can use the resulting SVG to render the PDF page into an image using resvg
  • Extracting text from PDF pages (auto-decodes Unicode, line breaks and text positions)
  • XHTML layouting for simple page layout (using azul-layout + xmlparser)
    • Good enough for basic page layouting, book rendering, reports and forms, with automatic page-breaking

NOT supported are:

  • Gradients
  • Patterns
  • File attachements
  • Open Prepress Interface
  • Halftoning images
  • Conformance / error checking for various PDF standards
  • Embedded Javascript

See the WASM32 demo live at: https://fschutt.github.io/printpdf

Writing PDF

Basic example

rust
use printpdf::*;

fn main() {
    let mut doc = PdfDocument::new("My first PDF");
    let page1_contents = vec![Op::Marker { id: "debugging-marker".to_string() }];
    let page1 = PdfPage::new(Mm(210.0), Mm(297.0), page1_contents);
    let mut warnings = Vec::new();
    let pdf_bytes: Vec = doc
        .with_pages(vec![page1])
        .save(&PdfSaveOptions::default(), &mut warnings);
}

Graphics

…

Images

  • Images only get compressed in release mode. You might get huge PDFs (6 or more MB) in debug mode.
  • To make this process faster, use BufReader instead of directly reading from the file.
  • Scaling of images is implicitly done to fit one pixel = one dot at 300 dpi.
…

Fonts

…

Tables, HTML

For creating tables, etc. printpdf uses a basic layout system, similar to wkhtmltopdf (although more limited in terms of features). It's good enough for basic page layouting, book rendering and reports / forms / etc. Includes automatic page-breaking.

Since printpdf supports WASM, there is an interactive demo at https://fschutt.github.io/printpdf - try playing with the XML.

See SYNTAX.md for the XML syntax description.

…

Roadmap

The goal of printpdf is to be a general-use PDF library, such as libharu or similar. PDFs generated by printpdf should always adhere to a PDF standard, except if you turn it off. Currently, only the standard PDF/X-3:2002 is covered (i.e. valid PDF according to Adobe Acrobat). Over time, there will be more standards supported.

The printpdf wiki is live at: https://github.com/fschutt/printpdf/wiki

Here are some resources I found while working on this library:

  • PDFXPlorer, shows the DOM tree of a PDF, needs .NET 2.0
  • Official PDF 1.7 reference
  • [GERMAN] How to embed unicode fonts in PDF
  • PDF X/1-a Validator
  • PDF X/3 technical notes

License / Support

Library is licensed MIT.

You can donate (one-time or recurrent) at https://github.com/sponsors/fschutt. Thanks!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rusthtml2pdfpdfpdf-generationpdf-reader

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架