ToPdfNet 0.0.1
See the version list below for details.
dotnet add package ToPdfNet --version 0.0.1
NuGet\Install-Package ToPdfNet -Version 0.0.1
<PackageReference Include="ToPdfNet" Version="0.0.1" />
<PackageVersion Include="ToPdfNet" Version="0.0.1" />
<PackageReference Include="ToPdfNet" />
paket add ToPdfNet --version 0.0.1
#r "nuget: ToPdfNet, 0.0.1"
#:package ToPdfNet@0.0.1
#addin nuget:?package=ToPdfNet&version=0.0.1
#tool nuget:?package=ToPdfNet&version=0.0.1
ToPdfNet
ToPdfNet is a pure managed .NET and C# HTML-to-PDF converter for single-file and report-oriented HTML. It converts HTML strings, files, and streams to PDF without Chromium, headless Chrome, wkhtmltopdf, CEF, System.Drawing, WPF, SkiaSharp, native binaries, or external browser processes.
The library is designed for invoices, tabular reports, statements, simple letters, and server-side PDF generation where deployment simplicity matters more than browser-perfect 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 deterministic report structures: text, headings, paragraphs, simple blocks, lists, tables, borders, backgrounds, local images, and base64 data URI images.
It intentionally does not execute JavaScript, fetch remote network resources, or try to reproduce browser layout algorithms. For pixel-perfect webpage capture, use a browser-backed renderer in a separate application boundary.
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 ToPdfNet release with pure managed .NET HTML-to-PDF rendering, CLI tool, and sample gallery.