Skip to content

bob22z/to-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

to-pdf

About

Crates.io

API Docs

Installation

Add the following to Cargo.toml:

[dependencies]
to-pdf = { git = "https://github.com/bob22z/to-pdf" }

Usage

use to_pdf::ToPdf;

// Initialize with custom fonts
let font_path = PathBuf::from(".");
let to_pdf = ToPdf::new(&font_path).unwrap();

// Typst template & data
let template = r#"
    #let forecast(day) = block[
      #box(square(
        width: 2cm,
        inset: 8pt,
        fill: if day.weather == "sunny" {
          yellow
        } else {
          aqua
        },
        align(
          bottom + right,
          strong(day.weather),
        ),
      ))
      #h(6pt)
      #set text(22pt, baseline: -8pt)
      #day.temperature °#day.unit
    ]

    #forecast(json("main.json"))
"#;

let json = r#"
    {
      "weather": "sunny",
      "temperature": "23",
      "unit": "c"
    }
"#;


let now = time::OffsetDateTime::now_utc();

// Export to Pdf with typst text
let pdf_content = to_pdf
    .to_pdf(template.into(), Some(json.into()), now)
    .unwrap();

// Preview as Svg with typst text
let svg_content = to_pdf
    .to_svg(template.into(), Some(json.into()), now)
    .unwrap();

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages