Rust / WASM library for reading, writing and rendering PDF
Rust / WASM library for reading, writing and rendering PDF
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,htmlfeature) works for basic layouts - tables, page breaks, headers/footers - but is still evolving. For pixel-exact control, position PDF elements manually with ops.
image)svg2pdf crate internally)Experimental features:
resvgazul-layout + xmlparser)NOT supported are:
See the WASM32 demo live at: https://fschutt.github.io/printpdf
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);
}…BufReader instead of directly reading from the file.……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.
…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.0Library is licensed MIT.
You can donate (one-time or recurrent) at https://github.com/sponsors/fschutt. Thanks!
No open issues yet, or sync has not completed.