m2nj.HtmlToPdfConverter 1.1.0

dotnet add package m2nj.HtmlToPdfConverter --version 1.1.0
                    
NuGet\Install-Package m2nj.HtmlToPdfConverter -Version 1.1.0
                    
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="m2nj.HtmlToPdfConverter" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="m2nj.HtmlToPdfConverter" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="m2nj.HtmlToPdfConverter" />
                    
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 m2nj.HtmlToPdfConverter --version 1.1.0
                    
#r "nuget: m2nj.HtmlToPdfConverter, 1.1.0"
                    
#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 m2nj.HtmlToPdfConverter@1.1.0
                    
#: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=m2nj.HtmlToPdfConverter&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=m2nj.HtmlToPdfConverter&version=1.1.0
                    
Install as a Cake Tool

m2nj.HtmlToPdfConverter

m2nj.HtmlToPdfConverter converts HTML and CSS into PDF by invoking an installed Microsoft Edge or Google Chrome browser in headless mode.

This is the stable 1.1.0 release.

The package has no NuGet rendering dependency. The target machine must provide a compatible browser and allow the application to start it.

The library targets .NET 8. Support for other target frameworks is not declared.

Author

This package is created and maintained by m2nj.

Package ownership and copyright: m2nj, 2026.

Installation

dotnet add package m2nj.HtmlToPdfConverter --version 1.1.0

To create the NuGet package from this source project:

dotnet pack HtmlToPdfConverter.csproj --configuration Release --output release

Usage

using m2nj.HtmlToPdfConverter;

public async Task<byte[]> CreatePdfAsync(
    string html,
    CancellationToken cancellationToken)
{
    return await HtmlPdfHelper.ConvertHtmlToPdfAsync(
        html,
        new HtmlPdfOptions
        {
            PageWidth = 595,
            PageHeight = 842,
            Margin = 48,
            PrintBackground = true
        },
        cancellationToken);
}

An ASP.NET Core MVC action can return the bytes directly:

public async Task<IActionResult> Pdf(CancellationToken cancellationToken)
{
    var pdf = await HtmlPdfHelper.ConvertHtmlToPdfAsync(
        "<html><body><h1>Report</h1></body></html>",
        cancellationToken: cancellationToken);

    return File(pdf, "application/pdf", "report.pdf");
}

Runtime dependency: Edge or Chrome

This package requires a compatible Chromium-based browser executable to be installed on the machine where the application runs. The package does not include the browser.

The converter automatically searches common Microsoft Edge and Google Chrome installation paths on Windows and uses the first browser it finds. No browser path needs to be specified in your application code when a browser is installed in one of those locations. This works for desktop applications and server applications alike; the browser must be installed on the machine running the application.

BrowserPath is optional. Set it only when the browser is installed somewhere that automatic discovery does not check, such as a custom installation location:

new HtmlPdfOptions
{
    BrowserPath = @"C:\Program Files\Google\Chrome\Application\chrome.exe"
}

An invalid configured path causes conversion to throw FileNotFoundException. Without a configured path, automatic discovery is limited to the common Windows paths in the helper. Linux, macOS, and container deployments must provide a compatible browser executable path when automatic discovery does not find the browser; those environments are not verified by this package documentation. The application identity must also be allowed to execute the browser and write to the system temporary directory.

Important limitations

  • HTML and CSS are rendered by the installed browser, so output depends on its version and available fonts. Specific layout features such as Flexbox, Grid, and complex tables have not been independently tested by this project.
  • Page scripts run in the browser, but the helper does not expose a readiness condition or wait for application-specific asynchronous content. Dynamic content may not be ready when printing starts.
  • Browser-generated print headers and footers (such as the page title, URL, date, and page number) are disabled.
  • External images, stylesheets, and fonts must be reachable by the browser.
  • HTML can cause the browser to request network resources. Do not pass untrusted HTML to this helper without sanitizing it, and apply network egress restrictions when processing user-controlled content; the helper does not provide URL allowlisting or SSRF protection.
  • Each conversion starts a separate browser process and profile. The helper does not pool browsers or limit concurrent conversions; applications handling concurrent requests should apply their own concurrency limits and monitor resource use.
  • Browser behavior, process permissions, and deployment compatibility should be validated in the target hosting environment before production use.

Changes in 1.1.0

  • Added HtmlPdfOptions.BrowserPath to select a browser executable explicitly, including in deployments where automatic Windows path discovery does not apply.
  • PDF files no longer include browser-added page details such as the date, page title, web address, or page number.
  • Expanded documentation of runtime requirements, security considerations, concurrency, and unverified deployment scenarios.

Sample

Program.cs contains a deliberately large HTML sample with a document structure, headings, paragraphs, inline styles, colors, links, entities, line breaks, ordered and unordered lists, a table, a blockquote, a preformatted code block, a footer, and script/style elements. It is excluded from the library compilation and is not included in the NuGet package.

The sample is intended as a broad rendering smoke test. It is not a feature-compatibility, load, security, or production-readiness test.

License

The included custom m2nj Free Use and Distribution License permits commercial use and redistribution of the unmodified package. It restricts modifying, adapting, or extending the package and is not an OSI-approved open-source license. Review License.txt and consult appropriate legal counsel before adopting or redistributing it.

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.
  • net8.0

    • No dependencies.

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.1.0 108 11/1/2026
1.0.0 126 9/25/2026