typstsharp 0.14.2
dotnet add package typstsharp --version 0.14.2
NuGet\Install-Package typstsharp -Version 0.14.2
<PackageReference Include="typstsharp" Version="0.14.2" />
<PackageVersion Include="typstsharp" Version="0.14.2" />
<PackageReference Include="typstsharp" />
paket add typstsharp --version 0.14.2
#r "nuget: typstsharp, 0.14.2"
#:package typstsharp@0.14.2
#addin nuget:?package=typstsharp&version=0.14.2
#tool nuget:?package=typstsharp&version=0.14.2
typstsharp
A .NET 10.0 wrapper around the Typst rendering stack. The managed layer in src/typstsharp calls into the Rust typst_core crate via P/Invoke and exposes convenient helpers for C# consumers plus a simple CLI.
Using
A simple example:
#:package typstsharp@0.0.8
using typstsharp;
var compiler = TypstCompiler.FromSource("= Hello World!");
var result = compiler.Compile();
var file = result.Buffers[0];
await File.WriteAllBytesAsync("output.pdf", file);
Console.WriteLine("PDF generated: output.pdf");
// Open the generated PDF file (works on Windows)
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("output.pdf") { UseShellExecute = true });
A more complicated example where we bulk generate PDFs:
#:package typstsharp@0.0.8
using typstsharp;
var typstInput = """
#let (
first-name,
points-balance,
) = sys.inputs
#set page(header: align(
right + bottom,
text("Logo"),
))
#set text(font: "IBM Plex Sans")
Hello *#first-name,*
You have accrued
#underline[#points-balance]
GlorboCorp Rewards Points
last year!
""";
var compiler = TypstCompiler.FromSource(typstInput);
Directory.CreateDirectory("output");
var people = new Dictionary<string, int>
{
["Alice"] = 1200,
["Bob"] = 850,
["Charlie"] = 4300,
};
foreach (var (person, balance) in people)
{
compiler.SetSysInputs(new Dictionary<string, string>
{
["first-name"] = person,
["points-balance"] = balance.ToString(),
});
var result = compiler.Compile();
var file = result.Buffers[0];
await File.WriteAllBytesAsync($"output/output{person}.pdf", file);
Console.WriteLine($"PDF generated: output{person}.pdf");
}
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("output") { UseShellExecute = true });
You can easily use this inside of an ASP.Net Server (just ensure you lazy load and cache the TypstCompiler to reduce from 40ms to around 3ms for a normal compile).
Prerequisites
- .NET SDK 10.0 – required to build the managed projects.
- Rust toolchain with
cargoon yourPATH– used to build the nativetypst_corecdylib.
Building
# from the repository root
dotnet build typstsharp.sln
The build will automatically:
- Run
cargo build --releaseonsrc/typst_corefor each target runtime identifier (RID). By default, this includeswin-x64,linux-x64, and others. For local debug builds, it only builds for the host architecture. - Stage the produced native libraries under
obj/. - Add the libraries to the managed project's runtime assets so that
dotnet publish/dotnet packplace the files underruntimes/<rid>/native/in the final artifact. - For local development, the native binary for the host architecture is copied to the output directory of any project referencing
typstsharp, ensuring it's available for debugging.
You can override the target runtimes by setting the RustTargets property (e.g., dotnet build -p:RustTargets=win-x64).
Verifying the CLI
# after a successful build
dotnet run --project src/typstsharp.cli/typstsharp.cli.csproj
Because the Rust binary is registered as a runtime asset, typst_core.dll/libtypst_core.so will appear beside the CLI executable automatically.
Notes
- If you need to inspect the generated P/Invoke bindings, see
src/typstsharp/Bindings.g.cs(created viacsbindgenduring the Rust build script). - The native Rust layer is responsible for memory management of the Typst world. The
TypstCompilerclass isIDisposableand should be properly disposed to release native resources.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.14.2 | 227 | 12/19/2025 |
| 0.14.1 | 410 | 12/11/2025 |
| 0.0.8 | 186 | 11/25/2025 |
| 0.0.7 | 175 | 11/25/2025 |
| 0.0.6 | 182 | 11/24/2025 |
| 0.0.5 | 392 | 11/18/2025 |
| 0.0.3-typst0.14.0 | 349 | 11/18/2025 |
| 0.0.2-typst0.14.0 | 354 | 11/18/2025 |