pub fn render_template(
main_typ: String,
file_system: Arc<dyn RenderFileSystem>,
data: &Value,
) -> Result<RenderResult>Expand description
Render a Typst template to PDF
This is the main public API for template compilation. It takes a template string, a file system for resolving imports, and JSON data to inject into the template.
§Arguments
main_typ- The main Typst template content as a stringfile_system- File system abstraction for resolving imports and assetsdata- JSON data to inject into the template
§Returns
Returns a RenderResult containing either the PDF bytes (on success) or
detailed error information (on failure).
§Errors
This function can return various errors:
DataError- JSON serialization issuesCompilationError- Typst compilation failuresFileSystemError- File access issues during import resolution
§Example
use papermake::{render_template, typst::InMemoryFileSystem};
use std::sync::Arc;
let template = "Hello #data.name!";
let fs = Arc::new(InMemoryFileSystem::new());
let data = serde_json::json!({ "name": "World" });
let result = render_template(template.to_string(), fs, &data).unwrap();
if result.success {
println!("PDF generated: {} bytes", result.pdf.unwrap().len());
} else {
for error in result.errors {
println!("Error: {}", error);
}
}