graphitepdf-kit 0.4.0

A core PDF generation library for Rust: document building, text, vector graphics, images, and more.
Documentation

Overview

graphitepdf-kit provides low-level but ergonomic PDF generation capabilities for Rust. It is designed for systems-level use and integration with the GraphitePDF layout engine.


Scope

graphitepdf-kit contains:

  • PDF document building with DocumentBuilder and Page
  • Vector graphics (shapes, paths, colors) with Canvas
  • Text rendering with standard fonts via TextBuilder
  • Page sizing (A series, Letter, custom) with PageSize
  • Metadata support with Metadata
  • Compressed content streams via flate2

Installation

cargo add graphitepdf-kit

API Summary

Category Items
Document DocumentBuilder, Page
Pages & Layout PageSize, PageMargins
Text TextBuilder, TextAlignment
Vector Graphics Canvas, Color, GraphicsState
Metadata Metadata

Example

use graphitepdf_kit::{
    DocumentBuilder,
    PageSize,
    TextBuilder,
    Canvas,
    Color,
    Metadata,
};

fn main() {
    // Build text content
    let text = TextBuilder::new()
        .font("F1", 24.0)
        .position(100.0, 700.0)
        .text("Hello from graphitepdf-kit!")
        .finish();

    // Build vector content
    let graphics = Canvas::new()
        .set_fill_color(Color::BLUE)
        .rect(100.0, 650.0, 200.0, 20.0)
        .fill()
        .set_stroke_color(Color::RED)
        .set_line_width(2.0)
        .rect(320.0, 650.0, 200.0, 20.0)
        .stroke()
        .finish();

    // Combine content
    let content = [text, graphics].concat();

    // Build and save document
    DocumentBuilder::new()
        .metadata(Metadata::new()
            .title("Sample PDF")
            .author("GraphitePDF")
            .subject("Rust PDF Generation")
        )
        .with_page(PageSize::A4, content)
        .save("output.pdf")
        .expect("Failed to write PDF");
}

Design Principles

  • Native Rust implementation with zero PDF library dependencies
  • Explicit APIs over implicit magic
  • Zero-cost abstractions where possible
  • Minimal and focused dependencies
  • Clear integration points for GraphitePDF layout engine

Role In GraphitePDF

graphitepdf-kit is the core PDF generation crate used by the main GraphitePDF library to convert laid-out content into final PDF files. It can also be used standalone for basic PDF generation tasks.


License

MIT