Skip to main content

Crate typst_laravel

Crate typst_laravel 

Source
Expand description

Typst for Laravel Rust: PDFs and images rendered in-process, without Chrome.

Templates are Typst files in resources/pdf. Each one reads the data it is rendered with from data.cbor:

#let invoice = cbor("data.cbor")

Invoice #invoice.number

Register TypstServiceProvider, then inject Typst and return what it renders:

use laravel::container::Inject;
use typst_laravel::{Pdf, Typst};

async fn show(typst: Inject<Typst>) -> laravel::Result<Pdf> {
    typst.pdf("invoice", &serde_json::json!({ "number": "INV-7" })).await
}

Structsยง

Pdf
A rendered PDF and its bytes. Returned from a handler, it opens in the browser.
Png
A rendered PNG and its bytes, which a handler may return as they are.
Typst
Renders Typst templates.
TypstServiceProvider
Registers Typst for the templates in resources/pdf, and the typst:template command.