Awrosoft.Utilities.HtmlToQuestPDF is a robust C# library, forked from Relorer/HTMLToQPDF, designed to seamlessly generate PDF documents from HTML content using the powerful QuestPDF library.
This fork extends the original functionality, enhancing support for common HTML elements and attributes to meet practical document generation needs.
Developed and maintained by Awrosoft.
QuestPDF excels at programmatic PDF generation but lacks native HTML rendering capabilities. Awrosoft.Utilities.HtmlToQuestPDF
bridges this gap by offering a lightweight HTML parser that interprets a subset of commonly used HTML tags and inline CSS styles, transforming them into corresponding QuestPDF structures.
This enhanced version introduces support for:
-
Inline
<span>
Styles:color
: Apply custom text color.font-weight
: Supportsbold
styling.font-style
: Supportsitalic
styling.text-decoration
: Supportsunderline
andline-through
effects.
-
Table Enhancements:
border="1"
: Draws borders around table cells.cellpadding
: Adds internal padding for better cell spacing.
-
Image Attributes:
width
andheight
: Set image dimensions directly.
-
Table Structure Improvements:
- Basic support for
colspan
androwspan
attributes in<td>
and<th>
elements.
- Basic support for
Please note that QuestPDF does not provide full HTML/CSS rendering.
This library serves as a partial parser, targeting a limited subset of HTML and inline styles suitable for common scenarios like:
- Formatted text (bold, italic, underlined)
- Simple tables with styling
- Inline images
Complex layouts, external stylesheets, JavaScript, and advanced HTML5/CSS3 features are not supported.
Here is a simple example demonstrating how to use the Html()
extension method inside your QuestPDF document generation logic, including basic error handling:
using Awrosoft.Utilities.HtmlToQuestPDF; // Import the namespace
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
// ... within your document generation logic
page.Content().Html(handler =>
{
try
{
if (!string.IsNullOrEmpty(myHtml))
{
handler.SetHtml(myHtml);
}
}
catch (Exception ex)
{
handler.SetHtml("<p><b>Error rendering content. Please contact support.</b></p>");
}
});
Contributions, issues, and feature requests are warmly welcome!
Feel free to open an issue or pull request. Check the Issues Page to see current topics.
This project is distributed under the MIT License. See the LICENSE file for details.