PlainHtmlToPdf 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package PlainHtmlToPdf --version 1.0.3
                    
NuGet\Install-Package PlainHtmlToPdf -Version 1.0.3
                    
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="PlainHtmlToPdf" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PlainHtmlToPdf" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="PlainHtmlToPdf" />
                    
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 PlainHtmlToPdf --version 1.0.3
                    
#r "nuget: PlainHtmlToPdf, 1.0.3"
                    
#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 PlainHtmlToPdf@1.0.3
                    
#: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=PlainHtmlToPdf&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=PlainHtmlToPdf&version=1.0.3
                    
Install as a Cake Tool

PlainHtmlToPdf

PlainHtmlToPdf is a .NET library designed to generate PDFs from HTML content. It leverages the power of PdfSharpCore to create high-quality PDF documents with support for custom fonts, CSS styling, and more.

Features

  • Generate PDFs from HTML content.
  • Support for custom font mappings.
  • CSS DOM tree generation for styling.
  • Integration with PdfSharpCore for PDF rendering.

Usage

Generate PDF from HTML

var pdfGenerator = new PdfGenerator();

var pdfDocument = pdfGenerator.GeneratePdf(htmlContent, new PdfGenerateConfig
{
    PageSize = PdfSharpCore.PageSize.A4,
    Margin = 20
});

// Save the PDF to a file
pdfDocument.Save("output.pdf");

Generating Base64 PDF from HTML

var pdfGenerator = new PdfGenerator("Segoe UI");

var result = string.Empty;
using (var stream = new MemoryStream())
{
    var pdf = pdfGenerator.GeneratePdf(htmlContent, new PdfGenerateConfig
    {
        PageSize = PdfSharpCore.PageSize.A4,
        Margin = 20
    });

    pdf.Save(stream);

    result = Convert.ToBase64String(stream.ToArray());
}

Known Issues

  • The library does not support all HTML and CSS features. Complex layouts and advanced CSS may not render as expected.
  • Some HTML elements may not be fully supported, leading to unexpected rendering in the PDF. (e.g., JavaScript, SVGs, css display: flex; ...)

Documentation

HtmlRenderer: https://archive.codeplex.com/?p=htmlrenderer

PdfSharpCore: https://github.com/ststeiger/PdfSharpCore

License

This project is licensed under the MIT License. See the LICENSE file for details.

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 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.5 218 6/3/2025
1.0.4 138 6/3/2025
1.0.3 145 5/28/2025
1.0.2 141 5/28/2025
1.0.1 145 5/28/2025
1.0.0 140 5/28/2025