Skip to content

Air9420/pdfmake_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

202 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdfmake_rust

Rust library for generating PDF documents. Inspired by the JavaScript pdfmake library.

Features

  • Pure Rust, no C dependencies
  • Builder API for easy document construction
  • Tables with cell spanning (colSpan, rowSpan)
  • Lists (ordered, unordered)
  • Images (PNG, JPEG)
  • SVG rendering
  • QR codes
  • Text wrapping and alignment
  • Page headers and footers (static and dynamic)
  • CJK font support (register TTF files)
  • Font subsetting (only used glyphs are embedded)
  • Named styles for consistent formatting
  • Feature flags for optional components

Installation

Add to your Cargo.toml:

[dependencies]
pdfmake_rust = "0.1.0"

Quick Start

use pdfmake_rust::{Document, DocumentNode, Margins, PageSize, PdfMake, TextNode};
use std::fs;

fn main() {
    let doc = Document::builder()
        .page_size(PageSize::a4())
        .page_margins(Margins::all(40.0))
        .content(DocumentNode::Text(TextNode::new("Hello, World!")))
        .build();

    let pdf = PdfMake::new();
    let bytes = pdf.render(&doc).expect("Failed to render PDF");

    fs::write("output.pdf", &bytes).expect("Failed to write PDF");
}

More Examples

See the examples/ directory for complete examples:

  • hello_world - Basic document
  • table - Table with spanning
  • invoice - Real-world invoice layout
  • multi_column - Multi-column layout

Run examples with:

cargo run --example hello_world
cargo run --example table
cargo run --example invoice

Feature Flags

Optional components can be enabled/disabled via feature flags:

[dependencies]
pdfmake_rust = { version = "0.1.0", default-features = false, features = ["svg", "image", "qr"] }
Feature Default Description
svg Yes SVG rendering support
image Yes PNG/JPEG image support
qr Yes QR code generation
encryption No PDF encryption (RC4, 128-bit)
tagged-pdf No Tagged PDF for accessibility (planned)

Architecture

The rendering pipeline follows these stages:

Document → normalize → measure → layout → render → PDF bytes
Stage Module Purpose
Model model.rs Document structure and builder API
Normalize normalize.rs Flatten document tree into blocks
Measure measure.rs Calculate text metrics, line wrapping
Layout layout.rs Position blocks into pages
Render render.rs Emit PDF 1.4 byte stream

CJK Font Support

Register CJK fonts to support Chinese, Japanese, Korean text:

let doc = Document::builder()
    .font("SimHei", "path/to/SimHei.ttf")
    .content(DocumentNode::Text(TextNode::new("你好世界")))
    .build();

Acknowledgments

This project is inspired by and references the JavaScript pdfmake library created by bpampuch and maintained by liborm85. The Rust implementation is written from scratch while following the same design principles.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

The original JavaScript pdfmake library is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages