NetHtml2Pdf 1.0.0
This package is under development, do not use
dotnet add package NetHtml2Pdf --version 1.0.0
NuGet\Install-Package NetHtml2Pdf -Version 1.0.0
<PackageReference Include="NetHtml2Pdf" Version="1.0.0" />
<PackageVersion Include="NetHtml2Pdf" Version="1.0.0" />
<PackageReference Include="NetHtml2Pdf" />
paket add NetHtml2Pdf --version 1.0.0
#r "nuget: NetHtml2Pdf, 1.0.0"
#:package NetHtml2Pdf@1.0.0
#addin nuget:?package=NetHtml2Pdf&version=1.0.0
#tool nuget:?package=NetHtml2Pdf&version=1.0.0
NetHtml2Pdf
A .NET library for converting HTML content to PDF using QuestPDF with extensible architecture.
Overview
NetHtml2Pdf is a modern, extensible HTML-to-PDF conversion library that supports various HTML elements including tables, paragraphs, line breaks, divisions, and sections. The library is designed to ensure maintainability, testability, and extensibility. The goal is to create a pure .NET cross-platform library that runs on Windows and Linux without requiring GDI+ dependencies.
Defaults
- Page size: Letter (8.5×11 in)
- Margins: 1 inch on all sides
- Font: Inter (bundled) for deterministic rendering
- CSS: minimal inline subset (e.g., color, background-color, border width, padding/margin, font-size, font-weight); unsupported properties are ignored
- Unsupported elements: ignored, inner text preserved
- Pagination: explicit via builder (no auto-pagination)
Quick Start
1. Install the Package
dotnet add package NetHtml2Pdf
2. Basic Usage (single page)
using NetHtml2Pdf;
var html = @"
<section>
<h1>My Document</h1>
<p>This is a sample document.</p>
</section>
<table>
<thead>
<tr><th>Name</th><th>Age</th></tr>
</thead>
<tbody>
<tr><td>Alice</td><td>30</td></tr>
<tr><td>Bob</td><td>25</td></tr>
</tbody>
</table>
";
var converter = new HtmlConverter();
var pdfBytes = await converter.ConvertToPdfBytes(html);
await File.WriteAllBytesAsync("output.pdf", pdfBytes);
3. Explicit Pagination (multi-page)
using NetHtml2Pdf;
var builder = new PdfDocumentBuilder();
builder.AddPdfPage("<section><h1>Page 1</h1><p>Hello</p></section>");
builder.AddPdfPage("<section><h1>Page 2</h1><p>World</p></section>");
var pdf = await builder.RenderAsync();
await File.WriteAllBytesAsync("multi-page.pdf", pdf);
4. Headers and Footers
Render a header and footer on every page using HTML fragments (same supported subset as body):
using NetHtml2Pdf;
var builder = new PdfDocumentBuilder();
builder.SetHeaderHtml("<div><strong>HeaderText</strong></div>");
builder.SetFooterHtml("<div><em>FooterText</em></div>");
builder.AddPdfPage("<section><h1>Page 1</h1><p>Alpha</p></section>");
builder.AddPdfPage("<section><h1>Page 2</h1><p>Beta</p></section>");
var pdf = await builder.RenderAsync();
await File.WriteAllBytesAsync("with-header-footer.pdf", pdf);
Styling notes
- Supported inline CSS in header/footer is the same minimal subset as body:
- text-align, padding, margin, color, font-size, font-weight/font-style
- Use <strong>/<em> for bold/italic; unsupported properties (e.g., display, position) are ignored.
- Height adapts to content; keep header/footer concise for predictable layout.
Example (right-aligned header, centered footer):
builder.SetHeaderHtml("<div style='text-align: right; padding: 8px; color: #333; font-size: 12px;'>My Company</div>");
builder.SetFooterHtml("<div style='text-align: center; padding: 6px; color: #666; font-size: 10px;'><em>Confidential</em></div>");
Dependencies
- QuestPDF: PDF generation library
- AngleSharp: HTML parsing library
- .NET 8.0: Target framework
Building and Testing
# Clone the repository
git clone <repository-url>
cd NetHtml2Pdf
# Restore dependencies
dotnet restore
# Build all projects
dotnet build
# Run tests
dotnet test
# Run console application
cd src/NetHtml2Pdf.TestConsole
dotnet run example.html
Contributing
- Fork the repository
- Create a feature branch
- Make your changes following good coding practices
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
| 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 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. |
-
net8.0
- NetHtml2Pdf.Parser (>= 1.0.0)
- NetHtml2Pdf.Renderer (>= 1.0.0)
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 |
|---|