ToPdfNet 0.0.2

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

ToPdfNet

ToPdfNet converts HTML to PDF in C# and .NET without a browser engine. It is a pure managed renderer for single-file and report-style HTML: no Chromium, wkhtmltopdf, native binaries, or external processes.

Use it for invoices, reports, statements, letters, and server-side PDFs where simple deployment matters more than pixel-perfect browser layout.

Install

dotnet add package ToPdfNet

Optional command-line tool:

dotnet tool install --global ToPdfNet.Cli

Library Usage

using ToPdfNet;

var pdf = ToPdf.FromHtml("""
<h1>Invoice INV-1001</h1>
<p><strong>Customer:</strong> Contoso Ltd</p>
<table>
  <tr><th>Description</th><th>Amount</th></tr>
  <tr><td>Managed PDF generation</td><td>$250.00</td></tr>
</table>
""");

File.WriteAllBytes("invoice.pdf", pdf);

Files and streams use the same API shape:

byte[] fromFile = ToPdf.FromHtmlFile("report.html");

await using var input = File.OpenRead("report.html");
byte[] fromStream = ToPdf.FromHtmlStream(input);

Rendering options control page size, margins, metadata, default font settings, and a CSS stylesheet string:

var options = new PdfRenderOptions
{
    Title = "Monthly Report",
    Author = "Reporting Service",
    PageSize = PdfPageSize.Letter,
    Margin = PdfMargin.FromInches(0.5),
    Stylesheet = "th { background-color: #eeeeee; } td, th { border: 1pt solid #cccccc; padding: 5pt; }"
};

byte[] pdf = ToPdf.FromHtmlFile("monthly-report.html", options);

CLI Usage

topdfnet samples/html/invoice.html -o invoice.pdf --title "Sample Invoice" --margin 0.6in

From the repository without installing the tool:

dotnet run --project src/ToPdfNet.Cli -- samples/html/invoice.html -o samples/pdf/invoice.pdf

Useful flags:

  • --stylesheet <path> applies a CSS file.
  • --page-size a4|letter|WIDTHxHEIGHT sets the page size.
  • --margin <length> sets equal margins, such as 0.5in, 12mm, or 36pt.
  • --title, --author, --subject, and --keywords set PDF metadata.

Samples

The samples/html folder contains examples from simple to dense:

  • simple-letter.html
  • invoice.html
  • profile.html
  • long-report.html
  • operations-report.html

Generated PDFs are checked into samples/pdf so people can inspect output without building the project first.

How It Works

ToPdfNet parses HTML with HtmlAgilityPack, resolves a small CSS subset, and draws PDF pages with PDFsharp. It supports report basics: text, headings, blocks, lists, tables, borders, backgrounds, local images, and base64 data URI images.

It does not run JavaScript, fetch remote resources, or emulate browser layout. For pixel-perfect webpage capture, use a browser-backed renderer.

Supported HTML And CSS

Supported:

  • Text, headings, paragraphs, divisions, spans, and line breaks.
  • Bold, italic, underline, basic font size, color, and alignment.
  • Lists, tables, table headers, simple borders, padding, and backgrounds.
  • Local images and data URI images supported by PDFsharp.
  • Page size, margins, document metadata, inline styles, and optional stylesheet text.

Unsupported by design:

  • JavaScript.
  • Browser layout features such as flexbox, grid, animations, and media queries.
  • Pixel-perfect webpage capture.
  • Remote network asset loading.
  • Native browser engines or platform-specific drawing stacks.

See docs/css-support.md and docs/limitations.md for details.

Repository Layout

src/ToPdfNet          Library package
src/ToPdfNet.Cli      dotnet tool package
tests/ToPdfNet.Tests  Focused behavior tests
samples/html          Example HTML inputs
samples/pdf           Generated sample PDFs
docs                  Public usage and support notes

Development

dotnet restore ToPdfNet.slnx
dotnet build ToPdfNet.slnx
dotnet test ToPdfNet.slnx
dotnet pack src/ToPdfNet/ToPdfNet.csproj -c Release
dotnet pack src/ToPdfNet.Cli/ToPdfNet.Cli.csproj -c Release

The GitHub workflows build, test, and pack on pull requests. NuGet publishing is handled by the release workflow when a v* tag is pushed or the workflow is run manually with a version.

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 was computed.  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.

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.2 126 6/23/2026
0.0.1 111 6/23/2026

Initial release with pure managed .NET HTML-to-PDF rendering, CLI tool, and sample gallery.