Getting Started

Install GlyphWeaveForge and convert your first Markdown file to PDF in minutes.

1. Add the dependency

Add to your Cargo.toml:

[dependencies]
glyphweaveforge = "0.1"

For Typst backend (recommended for production):

[dependencies]
glyphweaveforge = { version = "0.1", features = ["renderer-typst"] }

2. Basic conversion

Create a Forge builder, feed it markdown text, and call .convert():

use glyphweaveforge::Forge;

fn main() {
    let pdf = Forge::new()
        .from_text("# Hello\n\nThis is **bold** text.")
        .to_memory()
        .convert()
        .expect("conversion succeeded");

    // pdf.bytes contains the raw PDF data
    assert!(pdf.bytes.unwrap().starts_with(b"%PDF"));
}

3. From a file

Read Markdown from disk and save the PDF to a file:

use glyphweaveforge::Forge;

fn main() {
    Forge::new()
        .from_path("README.md")
        .to_file("output.pdf")
        .convert()
        .expect("conversion succeeded");
}

4. Choose a theme

Six built-in themes. Pass them via .with_theme():

use glyphweaveforge::{Forge, BuiltInTheme};

fn main() {
    Forge::new()
        .from_text("# Engineering Report")
        .to_file("report.pdf")
        .with_theme(BuiltInTheme::Engineering)
        .convert()
        .expect("conversion succeeded");
}

Available themes: Professional (default), Engineering, ScientificArticle, Invoice, Informational.

5. Typst backend (advanced)

Enable renderer-typst for professional typesetting with real math, custom fonts, and Mermaid diagrams:

use glyphweaveforge::{Forge, RenderBackendSelection, BuiltInTheme};

fn main() {
    Forge::new()
        .from_file("paper.md")
        .to_file("paper.pdf")
        .with_backend(RenderBackendSelection::Typst)
        .with_theme(BuiltInTheme::ScientificArticle)
        .convert()
        .expect("conversion succeeded");
}

6. Resource resolver (images, logos)

Resolve image paths dynamically — load from disk, a CDN, or generate on the fly:

use glyphweaveforge::Forge;

fn main() {
    let pdf = Forge::new()
        .from_text("![Logo](logo.png)")
        .to_memory()
        .with_resource_resolver(|href: &str| {
            if href == "logo.png" {
                Ok(vec![1, 2, 3])  // real bytes here
            } else {
                Err("not found".into())
            }
        })
        .convert()
        .expect("conversion succeeded");
}

7. Feature flags

FlagDescription
default = ["fs", "renderer-minimal"]File I/O + minimal backend
fsEnables from_path(), to_file(), to_dir()
renderer-minimalLightweight native renderer (no system deps)
renderer-typstTypst backend (real math, fonts, Mermaid)
typstAlias for renderer-typst
mathGFM math parsing + TeX-to-Typst conversion
mermaidRust-native Mermaid diagram renderer