Html2PDFGenerator 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Html2PDFGenerator --version 1.0.2
                    
NuGet\Install-Package Html2PDFGenerator -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Html2PDFGenerator" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Html2PDFGenerator" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Html2PDFGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Html2PDFGenerator --version 1.0.2
                    
#r "nuget: Html2PDFGenerator, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Html2PDFGenerator@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Html2PDFGenerator&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Html2PDFGenerator&version=1.0.2
                    
Install as a Cake Tool

🧾 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 VARBINARY column)

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.7 120 3/25/2026
1.0.6 112 3/17/2026
1.0.5 277 11/10/2025
1.0.4 203 11/7/2025
1.0.3 236 11/3/2025
1.0.2 231 11/3/2025
1.0.1 238 11/3/2025
1.0.0 230 11/3/2025