H2Pdf 0.0.1

dotnet add package H2Pdf --version 0.0.1
                    
NuGet\Install-Package H2Pdf -Version 0.0.1
                    
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="H2Pdf" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="H2Pdf" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="H2Pdf" />
                    
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 H2Pdf --version 0.0.1
                    
#r "nuget: H2Pdf, 0.0.1"
                    
#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 H2Pdf@0.0.1
                    
#: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=H2Pdf&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=H2Pdf&version=0.0.1
                    
Install as a Cake Tool

H2Pdf

๐Ÿš€ Generate production-ready PDFs using Razor components and C# in minutes.

CI NuGet License: MIT GitHub stars NuGet downloads

H2Pdf bridges modern .NET UI development and deterministic PDF generation. Build PDFs with familiar .razor components, strongly typed C#, and dependency injection.

โœจ Features

  • Razor components as PDF templates
  • Fluent PDF document model API
  • Optional HTML-to-PDF pipeline (HtmlPdfRenderer)
  • ASP.NET Core dependency injection integration
  • Cross-platform rendering (Windows, Linux, macOS)

๐Ÿš€ Quick Start (30 seconds)

Requirements: .NET 10 SDK

git clone https://github.com/evilz/H2Pdf.git
cd H2Pdf
dotnet build
cd samples/H2Pdf.Sample
dotnet run

Generated files:

  • sample-output.pdf
  • invoice-sample.pdf

๐Ÿ“ฆ Installation

Install via NuGet:

dotnet add package H2Pdf

Or clone from source:

git clone https://github.com/evilz/H2Pdf.git
cd H2Pdf
dotnet build

๐Ÿ“– Usage

var services = new ServiceCollection();
services.AddLogging();
services.AddH2Pdf();

var provider = services.BuildServiceProvider();
var renderer = provider.GetRequiredService<PdfRenderer>();

var parameters = new Dictionary<string, object?>
{
    ["Name"] = "Developer",
    ["Message"] = "This PDF was generated from a Razor component."
};

var document = await renderer.RenderToPdfAsync<HelloWorld>(parameters);
renderer.SaveToPdf(document, "output.pdf");

See samples/ and examples/ for complete usage patterns.

โšก Benchmark

Compare Playwright HTML-to-PDF with H2Pdf HTML-to-MigraDoc rendering:

dotnet build benchmarks/H2Pdf.Benchmarks
pwsh benchmarks/H2Pdf.Benchmarks/bin/Debug/net10.0/playwright.ps1 install chromium
dotnet run -c Release --project benchmarks/H2Pdf.Benchmarks

Environment

  • BenchmarkDotNet v0.14.0
  • .NET 10.0.2 (RyuJIT, AVX2)
  • Windows 11 x64
  • GC: Concurrent Workstation

๐Ÿงช Benchmarked Pipelines

  1. Playwright (Chromium)

    • HTML rendered in headless Chromium
    • PDF generated via Page.PdfAsync()
  2. MigraDoc (via HtmlPdfRenderer)

    • HTML โ†’ MigraDoc DOM
    • MigraDoc โ†’ PDF via PdfDocumentRenderer

๐Ÿ“ˆ Example output (single run)

Method Mean StdDev Gen0 Gen1 Allocated
PlaywrightHtmlToPdfAsync 9.231 ms 0.196 ms 15.63 - 188 KB
MigraDoc_HtmlToPdf 4.684 ms 0.014 ms 312.50 109.38 2.68 MB

These numbers are an example from one environment and one HTML payload.
Results will vary by machine, OS, runtime version, browser version, and template complexity.

โฑ Latency per PDF (example)

  • MigraDoc: ~4.68 ms
  • Playwright: ~9.23 ms

๐Ÿ“Š Stability (Jitter, example)

Pipeline StdDev
MigraDoc 0.014 ms
Playwright 0.196 ms

๐Ÿง  Memory Behavior (example)

Pipeline Allocated per PDF
Playwright ~188 KB
MigraDoc ~2.68 MB

GC activity:

  • MigraDoc โ†’ Triggers Gen0 + Gen1
  • Playwright โ†’ Mostly Gen0 only

Use benchmark output in your environment to compare trade-offs for your workloads.

๐Ÿง  Why this exists

Most PDF generation tools force teams to use low-level primitives or separate template systems. H2Pdf keeps PDF authoring in your existing .NET workflow with:

  • component-driven composition
  • familiar Razor syntax
  • predictable, code-reviewable output

๐Ÿ›ฃ Roadmap

See ROADMAP.md.

๐Ÿค Contributing

We welcome PRs and ideas. Start with CONTRIBUTING.md.

โญ Star History

Star History Chart

๐Ÿ— Architecture

High-level internals are documented in Architecture.md.

๐Ÿ“„ License

MIT โ€” see LICENSE.

Product Compatible and additional computed target framework versions.
.NET 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.

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.0.1 54 2/15/2026

Release notes will be added in upcoming releases.