typstsharp 0.14.2

dotnet add package typstsharp --version 0.14.2
                    
NuGet\Install-Package typstsharp -Version 0.14.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="typstsharp" Version="0.14.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="typstsharp" Version="0.14.2" />
                    
Directory.Packages.props
<PackageReference Include="typstsharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add typstsharp --version 0.14.2
                    
#r "nuget: typstsharp, 0.14.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package typstsharp@0.14.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=typstsharp&version=0.14.2
                    
Install as a Cake Addin
#tool nuget:?package=typstsharp&version=0.14.2
                    
Install as a Cake Tool

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 cargo on your PATH – used to build the native typst_core cdylib.

Building

# from the repository root
 dotnet build typstsharp.sln

The build will automatically:

  1. Run cargo build --release on src/typst_core for each target runtime identifier (RID). By default, this includes win-x64, linux-x64, and others. For local debug builds, it only builds for the host architecture.
  2. Stage the produced native libraries under obj/.
  3. Add the libraries to the managed project's runtime assets so that dotnet publish/dotnet pack place the files under runtimes/<rid>/native/ in the final artifact.
  4. 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 via csbindgen during the Rust build script).
  • The native Rust layer is responsible for memory management of the Typst world. The TypstCompiler class is IDisposable and should be properly disposed to release native resources.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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