A modernized fork of genpdfi with improved tests, documentation, and CI.
genpdfi_extended is a Rust library for programmatic PDF generation. It provides a
high-level API (Document, Element, Style, Paragraph, Table, Image, ...)
and lower-level rendering primitives in render for advanced usage.
- Font management with caching, embedding, and metrics (deterministic tests use bundled fonts in
fonts/). - Robust text serialization for embedded fonts: strings are emitted as full text so PDF viewers apply native kerning and text extractors can recover readable text (prevents glyph-id remapping issues when subsetting).
- Optional
imagesfeature to embed common image formats (PNG, JPEG, etc.). - Optional
latexfeature to render LaTeX formulas to SVG usingmicrotex_rsand embed them as images. - Optional
mermaidfeature to render Mermaid diagrams to SVG using a headless Chrome instance and embed them as images. - Executable doc examples (no
no_run/ignore) to improve documentation quality. - CI workflow that runs tests, generates Cobertura coverage (via tarpaulin) and publishes rustdoc to GitHub Pages.
use genpdfi_extended::{Document, elements, fonts};
let data = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/fonts/NotoSans-Regular.ttf")).to_vec();
let fd = fonts::FontData::new(data, None).expect("font data");
let family = fonts::FontFamily { regular: fd.clone(), bold: fd.clone(), italic: fd.clone(), bold_italic: fd.clone() };
let mut doc = Document::new(family);
doc.push(elements::Paragraph::new("Hello genpdfi_extended!"));
let mut buf = Vec::new();
doc.render(&mut buf).expect("render");
assert!(!buf.is_empty());- Run unit tests:
cargo test - Run tests including images:
cargo test --features images - Generate Cobertura coverage via tarpaulin:
cargo tarpaulin --features images --out Xml --output-dir .
# produces coverage/cobertura.xmlA GitHub Actions workflow (.github/workflows/ci.yml) is included that:
- builds and runs tests (with and without
images), - runs tarpaulin to generate
cobertura.xmland uploads it to Codecov using the slugsctg-development/genpdfi-extendedwithsecrets.CODECOV_TOKEN, - builds rustdoc and publishes it to
gh-pages(GitHub Pages).
Enable images to test and use image support:
cargo test --features images
cargo doc --features images --no-depsWhen using the mermaid feature, diagrams are rendered by a headless Chromium instance via the headless_chrome crate.
On first execution the crate may download a Chromium binary automatically; this can make the very first run noticeably longer and requires network access. If you prefer to avoid the download, install Chrome/Chromium system-wide and ensure it is available in PATH before running Mermaid examples.
- Format:
cargo fmt - Lint:
cargo clippy - Tests:
cargo testand coverage with tarpaulin - Use the bundled fonts in
fonts/for test determinism
See the LICENSES/ directory for included licenses.
If you want, I can add CI/docs badges to the README and commit & push these changes—what would you prefer?