ToPdfNet 0.0.2
dotnet add package ToPdfNet --version 0.0.2
NuGet\Install-Package ToPdfNet -Version 0.0.2
<PackageReference Include="ToPdfNet" Version="0.0.2" />
<PackageVersion Include="ToPdfNet" Version="0.0.2" />
<PackageReference Include="ToPdfNet" />
paket add ToPdfNet --version 0.0.2
#r "nuget: ToPdfNet, 0.0.2"
#:package ToPdfNet@0.0.2
#addin nuget:?package=ToPdfNet&version=0.0.2
#tool nuget:?package=ToPdfNet&version=0.0.2
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|WIDTHxHEIGHTsets the page size.--margin <length>sets equal margins, such as0.5in,12mm, or36pt.--title,--author,--subject, and--keywordsset PDF metadata.
Samples
The samples/html folder contains examples from simple to dense:
simple-letter.htmlinvoice.htmlprofile.htmllong-report.htmloperations-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 | 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 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. |
-
net10.0
- HtmlAgilityPack (>= 1.11.71)
- PDFsharp (>= 6.2.4)
-
net8.0
- HtmlAgilityPack (>= 1.11.71)
- PDFsharp (>= 6.2.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release with pure managed .NET HTML-to-PDF rendering, CLI tool, and sample gallery.