Html2PDFGenerator 1.0.2
See the version list below for details.
dotnet add package Html2PDFGenerator --version 1.0.2
NuGet\Install-Package Html2PDFGenerator -Version 1.0.2
<PackageReference Include="Html2PDFGenerator" Version="1.0.2" />
<PackageVersion Include="Html2PDFGenerator" Version="1.0.2" />
<PackageReference Include="Html2PDFGenerator" />
paket add Html2PDFGenerator --version 1.0.2
#r "nuget: Html2PDFGenerator, 1.0.2"
#:package Html2PDFGenerator@1.0.2
#addin nuget:?package=Html2PDFGenerator&version=1.0.2
#tool nuget:?package=Html2PDFGenerator&version=1.0.2
π§Ύ Html2PDFGenerator
Html2PDFGenerator is a lightweight .NET library that allows you to easily convert HTML strings into PDF.
Itβs simple, dependency-injected, and works seamlessly in ASP.NET Core projects.
π Features
- Convert HTML string β PDF bytes in just one line
- Works with ASP.NET Core dependency injection
- Supports complex HTML, CSS, and inline styles
- No external service required β fully local conversion
π¦ Installation
Install via NuGet Package Manager:
dotnet add package Html2PDFGenerator
powershell
Copy code
Install-Package Html2PDFGenerator
Or search for Html2PDFGenerator in Visual Studioβs NuGet Package Manager UI.
βοΈ Configuration
In your Program.cs (or Startup file if using older .NET):
using HTML2PDF;
var builder = WebApplication.CreateBuilder(args);
// Register PDF generator service
builder.Services.AddPDFGenerator();
var app = builder.Build();
π§ Usage Example
In your controller or service:
using Microsoft.AspNetCore.Mvc;
using HTML2PDF;
public class MyPDFController : Controller
{
private readonly IPDFGenerator _pdf;
public MyPDFController(IPDFGenerator pdf)
{
_pdf = pdf;
}
[HttpGet("generate-pdf")]
public IActionResult GeneratePDF()
{
string htmlContent = "<h1>Hello World π</h1><p>This is a sample PDF generated from HTML.</p>";
byte[] pdfBytes = _pdf.GeneratePDFFromHtml(htmlContent);
return File(pdfBytes, "application/pdf", "Sample.pdf");
}
}
π Output
The method returns a byte[] array representing the generated PDF.
You can:
- Return it as a downloadable file via
File() - Save it to disk using
File.WriteAllBytes() - Attach it to emails
- Store it in your database (as a
VARBINARYcolumn)
Example:
File.WriteAllBytes("C:\\Reports\\Invoice.pdf", pdfBytes);
π§© Requirements
- β .NET 8.0 or higher
- β Windows / Linux / macOS compatible
- β The package automatically loads wkhtmltopdf native DLLs (no manual setup required)
π§βπ» About the Author
Full-stack developer passionate about building clean, efficient, and developer-friendly tools for the .NET ecosystem. You can use this package freely in any project β feedback and improvements are always welcome!
β If you find this package helpful, please consider giving it a star on NuGet.org!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- DinkToPdf (>= 1.0.8)
- Microsoft.Extensions.DependencyInjection (>= 9.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.