ToPdfNet.Cli 0.0.2

dotnet tool install --global ToPdfNet.Cli --version 0.0.2
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local ToPdfNet.Cli --version 0.0.2
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=ToPdfNet.Cli&version=0.0.2
                    
nuke :add-package ToPdfNet.Cli --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|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 was computed.  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.

This package has no dependencies.

Version Downloads Last Updated
0.0.2 149 6/23/2026
0.0.1 119 6/23/2026

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