.NET bindings for Typst, the modern markup-based typesetting system.
Typst.Native lets you compile Typst documents to PDF, SVG, and PNG directly from .NET — no CLI installation or external processes required.
- Native performance: calls Typst's Rust core via P/Invoke (no WASM overhead)
- Cross-platform: ships pre-built native libraries for Windows, Linux, and macOS (x64 + ARM64)
- Zero external dependencies: everything is bundled in the NuGet package
- Idiomatic C# API:
TypstCompiler, diagnostics, streaming output
dotnet add package Typst.Nativeusing Typst.Native;
using var compiler = new TypstCompiler();
var result = compiler.Compile("Hello, *Typst* from .NET!");
if (result.IsSuccess)
{
byte[] pdf = result.ToPdf();
File.WriteAllBytes("output.pdf", pdf);
}
else
{
foreach (var diag in result.Diagnostics)
Console.Error.WriteLine(diag);
}Supply in-memory files — images, data files, or .typ modules — that your
Typst source can reference by path:
using var compiler = new TypstCompiler();
compiler.AddFile("logo.png", File.ReadAllBytes("logo.png"));
using var result = compiler.Compile("#image(\"logo.png\")");Typst accepts PNG, JPEG, GIF, WebP, SVG, and PDF as #image sources. Files on
disk also work when a root directory is set via SetRoot (or implicitly by
CompileFile); virtual files added with AddFile take precedence over disk
and persist until ClearFiles() is called or the compiler is disposed.
Render any page of a successful compilation to a PNG image:
using var result = compiler.Compile("Hello, PNG!");
byte[] png = result.RenderPng(pageIndex: 0, pixelsPerPoint: 2.0f); // 2.0 ≈ 144 DPI
File.WriteAllBytes("page1.png", png);| Runtime | NuGet RID | CI Runner |
|---|---|---|
| Windows x64 | win-x64 |
windows-latest |
| Linux x64 | linux-x64 |
ubuntu-latest |
| Linux ARM64 | linux-arm64 |
ubuntu-24.04-arm |
| macOS x64 | osx-x64 |
macos-latest (cross-compile) |
| macOS ARM64 | osx-arm64 |
macos-latest |
- .NET 8.0 SDK or later
- Rust toolchain (stable)
cd native/typst-ffi
cargo build --releaseThe shared library will be output to native/typst-ffi/target/release/.
dotnet build
dotnet testNote: To run tests locally, you need to first build the native library and place it in the appropriate
runtimes/{rid}/native/directory undersrc/Typst.Native.Runtime/.
Typst.Native/
├── native/typst-ffi/ # Rust FFI crate — thin C API over Typst
├── src/
│ ├── Typst.Native/ # Managed C# wrapper (main NuGet: Typst.Native)
│ ├── Typst.Native.Runtime/ # Native binaries package (Typst.Native.Runtime)
│ └── Typst.Native.Tests/ # Unit & integration tests
└── .github/workflows/ # CI/CD pipelines
| Package | Description |
|---|---|
Typst.Native |
Managed wrapper — the package you reference |
Typst.Native.Runtime |
Pre-built native libraries for all platforms |
The major and minor versions of the NuGet packages always match the major
and minor versions of the bundled Typst
compiler: Typst.Native 0.15.x compiles with Typst 0.15. The patch
version is independent and is incremented for fixes and improvements that
don't change the underlying Typst version.
When upgrading the Typst crates in native/typst-ffi/Cargo.toml, bump
VersionPrefix in Directory.Build.props accordingly.
Contributions are welcome! Please open an issue first to discuss what you'd like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes
- Push to the branch and open a Pull Request
This project is licensed under the MIT License.
Typst itself is licensed under the Apache License 2.0. See the Typst repository for details.