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.
- QuestPDF
- HtmlAgilityPack - used for HTML parsing
dotnet add package QuestPDF.HTML
Document.Create(container =>{container.Page(page =>{page.Content().Column(col =>{col.Item().HTML(handler =>{handler.SetHtml(html);});});});}).GeneratePdf(path);Recommended: Override the default image loading method for better performance and async support:
col.Item().HTML(handler =>{handler.OverloadImgReceivingFunc(GetImgBySrc);handler.SetHtml(html);});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));Set vertical padding for top-level lists (does not apply to nested lists):
handler.SetListVerticalPadding(40);| 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 |
| 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 |
The library supports parsing inline style attributes on HTML elements.
color- Text colorbackground-color- Text backgroundfont-size- Font size (px, pt, em, rem, cm, mm, in)font-weight- Bold, normal, light, or numeric (100-900)font-style- Italic, normalfont-family- Font family nametext-decoration- Underline, line-throughletter-spacing- Letter spacingline-height- Line height
padding,padding-top,padding-bottom,padding-left,padding-rightmargin(converted to padding)background-colorborder,border-colorwidth,height,min-width,max-width,min-height,max-heighttext-align- Left, center, right
- Hex:
#RGB,#RRGGBB,#RRGGBBAA - RGB:
rgb(r, g, b),rgba(r, g, b, a) - Named colors:
red,blue,green, etc.
<pstyle="color: #e74c3c; font-size: 18px; font-weight: bold;">
Styled text with CSS
</p><divstyle="background-color: #f0f0f0; padding: 10px; border: 1px;">
Container with background and padding
</div>You can use HTMLToQPDF.Example to try out the capabilities of this extension.
| Default Styles | Options for changing styles |
![]() | ![]() |
See CHANGELOG.md for version history and release notes.
MIT License - see the LICENSE file for details.
Originally created by Relorer.


