QuestPDF.HTML 1.5.0

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

QuestPDF.HTML

QuestPDF.HTML is an extension for QuestPDF that allows you to generate PDF from HTML.

QuestPDF currently does not support inserting HTML into a PDF document. This library fills that gap. While it doesn't support the full functionality of HTML and CSS, it covers most common use cases.

Dependencies

Installation

dotnet add package QuestPDF.HTML

Usage

Basic Example

Document.Create(container =>
{
    container.Page(page =>
    {
        page.Content().Column(col =>
        {
            col.Item().HTML(handler =>
            {
                handler.SetHtml(html);
            });
        });
    });
}).GeneratePdf(path);

Custom Image Loading

Recommended: Override the default image loading method for better performance and async support:

col.Item().HTML(handler =>
{
    handler.OverloadImgReceivingFunc(GetImgBySrc);
    handler.SetHtml(html);
});

Custom Styles

You can customize text and container styles for specific HTML tags:

handler.SetTextStyleForHtmlElement("div", TextStyle.Default.FontColor(Colors.Grey.Medium));
handler.SetTextStyleForHtmlElement("h1", TextStyle.Default.FontColor(Colors.DeepOrange.Accent4).FontSize(32).Bold());
handler.SetContainerStyleForHtmlElement("table", c => c.Background(Colors.Pink.Lighten5));
handler.SetContainerStyleForHtmlElement("ul", c => c.PaddingVertical(10));

List Padding

Set vertical padding for top-level lists (does not apply to nested lists):

handler.SetListVerticalPadding(40);

Supported HTML Elements

Block Elements

Tag Description
div Generic container
p Paragraph
h1 - h6 Headings (with default font sizes)
ul, ol, li Lists (unordered, ordered, list items)
table, thead, tbody, tr, th, td Tables (with colspan/rowspan support)
blockquote Block quotation with left border
pre Preformatted text (preserves whitespace, monospace font)
hr Horizontal rule
section, header, footer Semantic containers

Inline Elements

Tag Description
a Hyperlinks
b, strong Bold text
i, em Italic text
u Underlined text
s, strike, del Strikethrough text
sub, sup Subscript/superscript
small Smaller text
br Line break
img Images (supports URLs and base64)
span Inline container
code Inline code (monospace with background)
kbd Keyboard input
mark Highlighted text
abbr Abbreviation
q Inline quotation
var Variable
samp Sample output

CSS Inline Style Support

The library supports parsing inline style attributes on HTML elements.

Supported Text Properties

  • color - Text color
  • background-color - Text background
  • font-size - Font size (px, pt, em, rem, cm, mm, in)
  • font-weight - Bold, normal, light, or numeric (100-900)
  • font-style - Italic, normal
  • font-family - Font family name
  • text-decoration - Underline, line-through
  • letter-spacing - Letter spacing
  • line-height - Line height

Supported Container Properties

  • padding, padding-top, padding-bottom, padding-left, padding-right
  • margin (converted to padding)
  • background-color
  • border, border-color
  • width, height, min-width, max-width, min-height, max-height
  • text-align - Left, center, right

Supported Color Formats

  • Hex: #RGB, #RRGGBB, #RRGGBBAA
  • RGB: rgb(r, g, b), rgba(r, g, b, a)
  • Named colors: red, blue, green, etc.

Example

<p style="color: #e74c3c; font-size: 18px; font-weight: bold;">
    Styled text with CSS
</p>
<div style="background-color: #f0f0f0; padding: 10px; border: 1px;">
    Container with background and padding
</div>

Example Application

You can use HTMLToQPDF.Example to try out the capabilities of this extension.

<p align="center"> <img src="https://user-images.githubusercontent.com/26045342/195960914-1aef2f7e-f5bb-4c4b-bbe9-cd4770a0527f.png" /> </p>

<table border="0"> <tr> <td><b style="font-size:30px">Default Styles</b></td> <td><b style="font-size:30px">Options for changing styles</b></td> </tr> <tr> <td><img src="https://user-images.githubusercontent.com/26045342/195960950-8bf101e9-c64e-482c-9993-39f9646d0e2f.png" /></td> <td><img src="https://user-images.githubusercontent.com/26045342/195960936-6f014456-a074-4672-aa39-03cdcdcc3afc.png" /></td> </tr> </table>

Changelog

See CHANGELOG.md for version history and release notes.

License

MIT License - see the LICENSE file for details.

Credits

Originally created by Relorer.

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.5.0 5,898 2/6/2026
1.4.5 11,038 1/7/2026
1.4.4 515 1/7/2026
1.4.3 424 1/7/2026
1.4.2 59,759 3/24/2025
1.4.1 6,895 3/19/2025
1.4.0 2,079 3/5/2025
1.3.1 7,024 12/9/2024
1.3.0 1,351 11/28/2024
1.2.0 6,654 6/18/2024
1.0.0 5,686 1/23/2024

v1.5.0:
- Added new HTML tags: span, blockquote, pre, code, hr, mark, abbr, kbd, samp, var, q
- Added CSS inline style parsing support for text and container properties
- Supported CSS properties: color, background-color, font-size, font-weight, font-style, font-family, text-decoration, padding, margin, border, width, height, text-align
- Supported color formats: hex, rgb(), rgba(), named colors
- Supported length units: px, pt, em, rem, cm, mm, in, %

For full changelog see: https://github.com/JeremyVm/HTMLToQPDF/blob/master/CHANGELOG.md