Giter Site home page Giter Site logo

to-pdf's Introduction

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

to-pdf's People

Contributors

nottxy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.