Developers searching for PdfSharp HTML to PDF conversion encounter a frustrating reality: PdfSharp itself has no HTML support whatsoever. The commonly suggested workaround, HtmlRenderer.PdfSharp, implements only CSS 2.1 specification from 2011, a standard now over fifteen years old. This means Flexbox, CSS Grid, modern selectors, transforms, web fonts, and virtually every CSS feature developers rely on today will not render correctly.
This article documents the architectural limitation of PdfSharp, explains the severe CSS restrictions of HtmlRenderer.PdfSharp, and demonstrates why real-world HTML templates break. For developers who need modern CSS support, an alternative approach using browser-based rendering is presented.
The Core Problem: PdfSharp Has Zero HTML Support
PdfSharp is a low-level PDF manipulation library designed for programmatic document creation. The library provides methods to draw text, graphics, shapes, and images on PDF pages using coordinate-based positioning. What it does not provide is any capability to parse or render HTML content.
The official PdfSharp FAQ addresses this directly:
"Can I use PDFsharp to convert HTML or RTF to PDF? No, not 'out of the box', and we do not plan to write such a converter in the near future."
— PDFsharp Documentation FAQ
This is not a missing feature or planned enhancement. HTML conversion is explicitly out of scope for the library. Developers who need HTML-to-PDF functionality must integrate third-party solutions, with HtmlRenderer.PdfSharp being the most common choice.
What PdfSharp Actually Does
PdfSharp provides:
- Low-level PDF document creation and manipulation
- Drawing text with specified fonts, sizes, and positions
- Rendering graphics, shapes, and images
- PDF merging, splitting, and page manipulation
- Form field creation and modification
- PDF security and encryption
What PdfSharp Cannot Do
PdfSharp cannot:
- Parse HTML markup
- Interpret CSS stylesheets
- Execute JavaScript
- Convert URLs to PDF
- Render web page content
- Process any markup language
Any Stack Overflow answer, blog post, or forum thread suggesting PdfSharp can handle HTML conversion is referring to the separate HtmlRenderer.PdfSharp library, which has its own severe limitations.
HtmlRenderer.PdfSharp: CSS 2.1 Only
HtmlRenderer.PdfSharp is a third-party library that bridges HtmlRenderer's custom parsing engine with PdfSharp's PDF output. The library explicitly supports only HTML 4.01 and CSS Level 2 specifications.
CSS Level 2 became a W3C Recommendation in 1998, with CSS 2.1 (the version HtmlRenderer targets) finalized in 2011. This predates:
- CSS Flexbox (Candidate Recommendation 2012, widespread adoption 2015)
- CSS Grid Layout (W3C Recommendation 2017)
- CSS Transforms (W3C Recommendation 2013)
- CSS Variables (W3C Recommendation 2015)
- CSS Calc function (2012)
- Modern pseudo-selectors (
:nth-child,:not,:has)
The practical impact is that any HTML template designed in the last decade using modern layout techniques will not render correctly.
Installation and Basic Usage
HtmlRenderer.PdfSharp is available as a NuGet package:
Install-Package HtmlRenderer.PdfSharp
Basic conversion appears straightforward:
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
public class BasicHtmlRendererExample
{
public void ConvertSimpleHtml()
{
string html = @"
<html>
<body>
<h1>Simple Document</h1>
<p>This basic HTML will render.</p>
</body>
</html>";
// Generate PDF using HtmlRenderer.PdfSharp
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
pdf.Save("simple-output.pdf");
}
}
This works for trivial HTML. The problems emerge when developers attempt to use CSS features from the last fifteen years.
CSS Features That Do Not Work
The following sections document CSS features that HtmlRenderer.PdfSharp cannot process. Each example shows code that will render incorrectly or not at all.
Flexbox Layout (display: flex)
CSS Flexbox is the most common layout system for modern web development. HtmlRenderer.PdfSharp completely ignores Flexbox properties.
/* This CSS will be completely ignored */
.container {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 20px;
}
.item {
flex: 1;
flex-basis: 200px;
flex-grow: 1;
flex-shrink: 0;
}
When this CSS is processed by HtmlRenderer.PdfSharp:
-
display: flexis ignored; elements render as block elements -
justify-content,align-items,flex-wraphave no effect -
gapbetween flex items is not applied -
flex,flex-basis,flex-grow,flex-shrinkare ignored - Items stack vertically instead of arranging in a row
A header layout like this:
<div class="header" style="display: flex; justify-content: space-between;">
<div class="logo">Company Name</div>
<div class="nav">Navigation Items</div>
</div>
Will render as two stacked blocks rather than side-by-side elements.
CSS Grid Layout (display: grid)
CSS Grid became a W3C Recommendation in 2017 and is essential for complex layouts. HtmlRenderer.PdfSharp has no Grid support.
/* All Grid properties are unsupported */
.dashboard {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto 1fr auto;
grid-gap: 20px;
grid-template-areas:
"header header header"
"sidebar main main"
"footer footer footer";
}
.sidebar {
grid-area: sidebar;
}
.main {
grid-column: span 2;
}
When rendered:
-
display: gridis ignored - All
grid-*properties have no effect -
grid-template-areasand named areas are not processed - Elements render in normal document flow
CSS Transforms
Transforms allow rotation, scaling, and skewing of elements. These are commonly used for watermarks, rotated text, and visual effects.
/* Transform properties are not supported */
.watermark {
transform: rotate(-45deg);
transform-origin: center center;
}
.scaled-logo {
transform: scale(1.5);
}
.skewed-banner {
transform: skewX(10deg);
}
.translated-element {
transform: translateX(50px);
}
All transform operations are ignored. Rotated watermarks will appear at 0 degrees. Scaled elements retain their original size.
CSS Variables (Custom Properties)
CSS Custom Properties provide theming and reusable values. HtmlRenderer.PdfSharp cannot process them.
/* CSS Variables are not interpreted */
:root {
--primary-color: #3498db;
--secondary-color: #2c3e50;
--spacing-unit: 16px;
--border-radius: 4px;
}
.button {
background-color: var(--primary-color);
padding: var(--spacing-unit);
border-radius: var(--border-radius);
}
Elements using CSS variables will receive no styling from those properties. Colors default to black, spacing to zero, and borders to none.
Calc() Function
The calc() function enables mathematical calculations in CSS values. HtmlRenderer.PdfSharp does not evaluate these expressions.
/* calc() is not evaluated */
.sidebar {
width: calc(100% - 250px);
}
.content {
padding: calc(10px + 2%);
margin-top: calc(50vh - 100px);
}
Properties using calc() will likely be ignored entirely or cause parsing errors.
Modern Pseudo-Selectors
Advanced selectors for targeting specific elements are not available.
/* These selectors do not work */
.table tr:nth-child(odd) {
background-color: #f2f2f2;
}
.table tr:nth-child(even) {
background-color: white;
}
.item:not(.active) {
opacity: 0.5;
}
.container > div:first-of-type {
margin-top: 0;
}
.parent:has(.child) {
border: 1px solid blue;
}
Alternating row colors, negation selectors, and relational selectors all fail. Developers must add explicit classes to each element or use inline styles.
Pseudo-Elements (::before, ::after)
Generated content using pseudo-elements is not supported.
/* Pseudo-elements do not render */
.quote::before {
content: '"';
font-size: 2em;
}
.quote::after {
content: '"';
font-size: 2em;
}
.required-field::after {
content: ' *';
color: red;
}
.clearfix::after {
content: '';
display: table;
clear: both;
}
Quote marks, required field indicators, and clearfix hacks using pseudo-elements will not appear in the output.
Box-Sizing Property
The box-sizing property affects how element dimensions are calculated. HtmlRenderer.PdfSharp's support is inconsistent.
/* box-sizing behavior is unreliable */
* {
box-sizing: border-box;
}
.container {
width: 300px;
padding: 20px;
border: 5px solid black;
/* With border-box, total width should be 300px */
/* Without border-box, total width becomes 350px */
}
Layout calculations may differ from browser rendering, causing elements to overflow or collapse unexpectedly.
Media Queries
Media queries for responsive design and print-specific styling have limited support.
/* Media queries are largely ignored */
@media print {
.no-print {
display: none;
}
.page-break {
page-break-before: always;
}
}
@media (max-width: 800px) {
.container {
flex-direction: column;
}
}
Print-specific media queries may have partial support, but breakpoint-based queries for responsive layouts do not function.
Web Fonts (@font-face)
Custom web fonts require manual embedding and configuration.
/* @font-face declarations may not load */
@font-face {
font-family: 'CustomFont';
src: url('custom-font.woff2') format('woff2'),
url('custom-font.woff') format('woff');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'CustomFont', Arial, sans-serif;
}
Google Fonts, Adobe Fonts, and self-hosted web fonts will not automatically load. Developers must manually embed font files and register them with the renderer. Fonts used in rendered HTML that are not found in installed or added fonts will be replaced by a fallback font.
SVG Rendering
Scalable Vector Graphics support is limited or nonexistent.
<!-- SVG elements may not render -->
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="#3498db"/>
<text x="50" y="55" text-anchor="middle">SVG</text>
</svg>
SVG icons, charts, and graphics embedded in HTML will not appear in the PDF output.
Complete Feature Comparison Table
| CSS Feature | CSS Level | Year Standardized | HtmlRenderer.PdfSharp Support |
|---|---|---|---|
| Basic selectors (class, id, element) | CSS 1 | 1996 | Yes |
| Colors, fonts, margins, padding | CSS 1/2 | 1996-1998 | Yes |
float, clear
|
CSS 2 | 1998 | Partial |
position: absolute/relative |
CSS 2 | 1998 | Partial |
| Basic table styling | CSS 2 | 1998 | Yes |
display: flex |
CSS 3 | 2012 | No |
display: grid |
CSS 3 | 2017 | No |
transform |
CSS 3 | 2013 | No |
| CSS Variables | CSS 3 | 2015 | No |
calc() |
CSS 3 | 2012 | No |
:nth-child() |
CSS 3 | 2011 | No |
::before, ::after
|
CSS 2.1/3 | 2011 | No |
box-sizing |
CSS 3 | 2012 | Inconsistent |
| Media queries | CSS 3 | 2012 | Limited |
@font-face |
CSS 3 | 2009 | Manual embedding required |
| Flexbox gap | CSS 3 | 2020 | No |
| CSS Grid | CSS 3 | 2017 | No |
| SVG rendering | HTML5 | 2014 | No |
| JavaScript execution | - | - | No |
Bootstrap and Tailwind Incompatibility
Modern CSS frameworks depend on CSS features that HtmlRenderer.PdfSharp cannot process.
Bootstrap 5
Bootstrap 5 uses Flexbox extensively for its grid system, utilities, and components.
<!-- Bootstrap 5 layout will break -->
<div class="container">
<div class="row">
<div class="col-md-6">Left Column</div>
<div class="col-md-6">Right Column</div>
</div>
</div>
<div class="d-flex justify-content-between">
<span>Left</span>
<span>Right</span>
</div>
Bootstrap's grid uses Flexbox with display: flex. The columns will not align horizontally. Utility classes like d-flex, justify-content-*, and align-items-* are all Flexbox-based and will have no effect.
Developers have reported this specific issue:
"The problem with bootstrap is that to align the columns use float: left and pdfsharp cannot read this property instead use display: inline-block and define the width in pixels."
— Developer workaround discussion
Even this workaround only applies to Bootstrap 3's float-based grid. Bootstrap 4 and 5 have migrated entirely to Flexbox.
Tailwind CSS
Tailwind CSS provides utility classes for rapid styling. Many of these utilities use unsupported CSS features.
<!-- Tailwind utilities that will fail -->
<div class="flex items-center justify-between space-x-4">
<div class="flex-1">Flexible item</div>
<div class="w-1/3">Fixed width</div>
</div>
<div class="grid grid-cols-3 gap-4">
<div>Grid item 1</div>
<div>Grid item 2</div>
<div>Grid item 3</div>
</div>
<div class="transform rotate-45 scale-150">
Transformed element
</div>
Flexbox utilities (flex, items-*, justify-*, flex-1), Grid utilities (grid, grid-cols-*, gap-*), and Transform utilities (transform, rotate-*, scale-*) will all be ignored.
What Renders as Garbage
When Bootstrap or Tailwind HTML is processed by HtmlRenderer.PdfSharp:
- Multi-column layouts collapse to single columns
- Centered content aligns to the left
- Flexible widths become 100% width
- Grid items stack vertically
- Spacing between items disappears
- Transformed elements appear untransformed
- Responsive breakpoints have no effect
The output does not resemble the browser preview at all.
GitHub Issues and Forum Reports
Developer frustration with HtmlRenderer.PdfSharp limitations is documented across multiple platforms.
Table Header Repetition Issue
A commonly reported problem involves table headers not repeating on subsequent pages.
"I have a table in my HTML section that overflows to the next page and I want the table columns to show on every page. I am trying to add CSS to make the table headers repeat:
thead { display: table-header-group !important; }but the Table columns are not appearing on second page."
— GitHub Issue #193{:rel="nofollow"}, HTML-Renderer Repository
The CSS for repeating table headers is either not supported or not functioning as expected.
External CSS Loading
Linking external stylesheets presents challenges.
"I've been trying to use external CSS with this library. I've tried to put the HTML and the CSS all in the string but it doesn't seem to work properly."
— GitHub Issue #65{:rel="nofollow"}, HTML-Renderer Repository
The workaround requires embedding all CSS inline rather than using <link> tags.
Letter-Spacing Not Working
Even CSS 2 properties can have inconsistent support.
"PDFSharp - letter-spacing CSS not working"
— Forum Topic{:rel="nofollow"}, PdfSharp Forums
The letter-spacing property, despite being part of CSS 2, does not function correctly.
Version Compatibility Issues
Updating library versions can break existing functionality.
"When using version PDFSharp 1.50.4545.0 type initializer throws an exception. The library works fine with PDFSharp version 1.32.3057."
— GitHub Issue #143{:rel="nofollow"}, HTML-Renderer Repository
Developers must carefully manage version compatibility between HtmlRenderer and PdfSharp packages.
.NET Core Compatibility Challenges
The original HtmlRenderer.PdfSharp targets .NET Framework. Developers using .NET Core, .NET 5, .NET 6, or .NET 8 must use community forks with varying support levels.
Available .NET Core Options
Several packages attempt to provide .NET Core support:
- HtmlRenderer.PdfSharp.NetStandard2: A .NET Standard 2.0 port
- HtmlRendererCore.PdfSharp: A .NET Core-specific fork
- PdfSharpCore + HtmlRendererCore: A combination requiring multiple packages
Each fork has its own maintenance status, version compatibility requirements, and potential bugs.
Installation Complexity
.NET Core projects require multiple packages:
Install-Package PdfSharpCore
Install-Package HtmlRendererCore.PdfSharp
Version conflicts between these packages can cause runtime errors. When PdfSharpCore updates, HtmlRendererCore may lag behind, creating dependency resolution failures.
System.Drawing Dependency
HtmlRenderer historically depends on System.Drawing.Common, which has platform limitations. On Linux and macOS, System.Drawing requires the libgdiplus library, which has known memory leaks and compatibility issues. Microsoft has marked System.Drawing.Common as Windows-only starting with .NET 6.
When HtmlRenderer.PdfSharp Is Acceptable
Despite significant limitations, HtmlRenderer.PdfSharp can work for specific constrained use cases.
Suitable Scenarios
- Simple invoices with table layouts: Basic tables without modern CSS
- Text-heavy documents: Documents primarily consisting of paragraphs and headings
- Internal tools: Where visual polish is not critical
- Legacy template maintenance: Existing templates already designed for CSS 2 limitations
- Budget-constrained projects: When licensing costs are prohibitive
Required Constraints
To use HtmlRenderer.PdfSharp successfully, developers must:
- Design HTML templates specifically for CSS Level 2
- Use table-based layouts instead of Flexbox or Grid
- Avoid all modern CSS features listed above
- Test output immediately rather than assuming browser preview matches
- Embed all CSS inline rather than using external stylesheets
- Manually embed any custom fonts
- Accept that complex layouts will require significant workarounds
Converting HTML to PDF with IronPDF
For developers who need to render modern HTML and CSS as they appear in browsers, IronPDF provides a fundamentally different architecture. Instead of a custom CSS parser limited to specifications from 2011, IronPDF embeds the Chromium rendering engine, the same engine powering Google Chrome.
Architectural Difference
HtmlRenderer.PdfSharp uses a custom parsing engine that interprets a subset of HTML and CSS specifications. This approach is lightweight but cannot keep pace with evolving web standards.
IronPDF embeds a headless Chromium browser. When HTML is submitted for rendering, Chromium processes it exactly as Chrome would display it in a browser window. This includes:
- Full HTML5 parsing
- CSS3 including Flexbox and Grid
- CSS Transforms and animations (static capture)
- CSS Variables and calc()
- Modern selectors (:nth-child, :not, etc.)
- Pseudo-elements (::before, ::after)
- JavaScript execution for dynamic content
- Web fonts via @font-face
- SVG rendering
- Media queries including print stylesheets
Code Example: Modern CSS Layout to PDF
The following example demonstrates rendering HTML with Flexbox and Grid layouts that HtmlRenderer.PdfSharp cannot process.
using IronPdf;
public class ModernCssToPdfConverter
{
public void ConvertModernHtmlToPdf()
{
// ChromePdfRenderer uses the embedded Chromium engine
var renderer = new ChromePdfRenderer();
// Configure page margins
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;
renderer.RenderingOptions.MarginLeft = 20;
renderer.RenderingOptions.MarginRight = 20;
// HTML content using CSS features that fail in HtmlRenderer.PdfSharp
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS Variables - Not supported by HtmlRenderer.PdfSharp */
:root {
--primary-color: #2c3e50;
--accent-color: #3498db;
--spacing: 16px;
}
body {
font-family: 'Segoe UI', Arial, sans-serif;
margin: 0;
padding: var(--spacing);
color: var(--primary-color);
}
/* Flexbox Header - Not supported by HtmlRenderer.PdfSharp */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--spacing);
border-bottom: 3px solid var(--accent-color);
margin-bottom: calc(var(--spacing) * 2);
}
.logo {
font-size: 1.8em;
font-weight: bold;
}
.invoice-info {
text-align: right;
}
/* CSS Grid Layout - Not supported by HtmlRenderer.PdfSharp */
.items-grid {
display: grid;
grid-template-columns: 3fr 1fr 1fr 1fr;
gap: 1px;
background-color: #ddd;
border: 1px solid #ddd;
margin-bottom: var(--spacing);
}
.grid-header {
background-color: var(--accent-color);
color: white;
padding: 12px;
font-weight: bold;
}
.grid-cell {
background-color: white;
padding: 12px;
}
/* nth-child selector - Not supported by HtmlRenderer.PdfSharp */
.grid-cell:nth-child(4n+1),
.grid-cell:nth-child(4n+2),
.grid-cell:nth-child(4n+3),
.grid-cell:nth-child(4n) {
border-bottom: 1px solid #eee;
}
/* Flexbox for totals row */
.totals {
display: flex;
justify-content: flex-end;
padding: var(--spacing);
background-color: #f8f9fa;
border-radius: 4px;
}
.total-amount {
font-size: 1.4em;
font-weight: bold;
}
/* Pseudo-element for required indicator */
.required::after {
content: ' *';
color: #e74c3c;
}
</style>
</head>
<body>
<div class='header'>
<div class='logo'>Acme Corporation</div>
<div class='invoice-info'>
<strong>Invoice #12345</strong><br>
Date: January 20, 2026<br>
Due: February 19, 2026
</div>
</div>
<p><span class='required'>Customer Name</span>: John Smith</p>
<div class='items-grid'>
<div class='grid-header'>Description</div>
<div class='grid-header'>Quantity</div>
<div class='grid-header'>Unit Price</div>
<div class='grid-header'>Total</div>
<div class='grid-cell'>Widget A - Premium Model</div>
<div class='grid-cell'>10</div>
<div class='grid-cell'>$25.00</div>
<div class='grid-cell'>$250.00</div>
<div class='grid-cell'>Widget B - Standard Edition</div>
<div class='grid-cell'>5</div>
<div class='grid-cell'>$45.00</div>
<div class='grid-cell'>$225.00</div>
<div class='grid-cell'>Professional Services</div>
<div class='grid-cell'>8 hrs</div>
<div class='grid-cell'>$150.00</div>
<div class='grid-cell'>$1,200.00</div>
</div>
<div class='totals'>
<span class='total-amount'>Total Due: $1,675.00</span>
</div>
</body>
</html>";
// Render HTML to PDF using Chromium engine
// All CSS features render correctly
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("invoice-modern-css.pdf");
}
}
This code produces a PDF with:
- Flexbox header layout with content justified to opposite ends
- CSS Grid table with properly aligned columns
- CSS Variables applied throughout the document
- calc() function evaluated correctly
- :nth-child selectors applying alternating styles
- ::after pseudo-element displaying the required indicator
The same HTML rendered through HtmlRenderer.PdfSharp would produce:
- Header items stacked vertically
- Grid items in a single column
- Variables unresolved (no colors, no spacing)
- calc() expressions causing layout errors
- No alternating row styles
- Missing required indicator
Converting Bootstrap 5 HTML
IronPDF renders Bootstrap 5 layouts correctly:
using IronPdf;
public class BootstrapToPdfConverter
{
public void ConvertBootstrapHtml()
{
var renderer = new ChromePdfRenderer();
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body class='p-4'>
<div class='container'>
<div class='row mb-4'>
<div class='col-md-6'>
<h1>Company Report</h1>
<p class='lead'>Q4 2025 Financial Summary</p>
</div>
<div class='col-md-6 text-end'>
<img src='https://via.placeholder.com/150x50' alt='Logo'>
</div>
</div>
<div class='row'>
<div class='col-md-4'>
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>Revenue</h5>
<p class='card-text display-6'>$1.2M</p>
</div>
</div>
</div>
<div class='col-md-4'>
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>Expenses</h5>
<p class='card-text display-6'>$800K</p>
</div>
</div>
</div>
<div class='col-md-4'>
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>Profit</h5>
<p class='card-text display-6 text-success'>$400K</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>";
// Bootstrap's Flexbox grid renders correctly
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("bootstrap-report.pdf");
}
}
The Bootstrap grid, card components, and utility classes all render as expected because IronPDF's Chromium engine processes them identically to a browser.
Converting a Web Page URL
IronPDF can capture live web pages including those with JavaScript-rendered content:
using IronPdf;
public class WebPageToPdfConverter
{
public void CaptureWebPage()
{
var renderer = new ChromePdfRenderer();
// Enable JavaScript for dynamic content
renderer.RenderingOptions.EnableJavaScript = true;
// Wait for JavaScript frameworks to initialize
renderer.RenderingOptions.WaitFor.RenderDelay(2000);
// Capture a live URL
var pdf = renderer.RenderUrlAsPdf("https://example.com/dashboard");
pdf.SaveAs("webpage-capture.pdf");
}
}
HtmlRenderer.PdfSharp cannot render URLs at all, as it only accepts HTML strings.
API Reference
For detailed documentation on IronPDF's rendering capabilities:
Migration Considerations
Licensing
PdfSharp is open source under the MIT License. HtmlRenderer.PdfSharp is also open source. IronPDF is commercial software with per-developer licensing. A free trial is available for evaluation, and a free tier exists for development purposes.
For projects requiring modern CSS support, the licensing cost is often offset by reduced development time from not having to work around CSS limitations.
API Migration
The migration from HtmlRenderer.PdfSharp to IronPDF is straightforward since both accept HTML strings:
HtmlRenderer.PdfSharp:
PdfDocument pdf = PdfGenerator.GeneratePdf(htmlContent, PdfSharp.PageSize.A4);
pdf.Save("output.pdf");
IronPDF:
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");
What You Gain
- Full CSS3 support including Flexbox and Grid
- JavaScript execution for dynamic content
- URL-to-PDF conversion capability
- Web font loading via @font-face
- SVG rendering
- Native .NET 6/8 support
- Active development and commercial support
What to Consider
- Commercial licensing required for production deployment
- Larger package size due to embedded Chromium
- Higher memory usage during rendering
- Initial learning curve for advanced configuration
Conclusion
PdfSharp has no native HTML support. The HtmlRenderer.PdfSharp workaround implements only CSS 2.1 specification, a standard finalized in 2011 that predates Flexbox, CSS Grid, CSS Variables, transforms, and modern selectors. Any HTML template using CSS features from the last fifteen years will not render correctly.
For developers who need to convert modern HTML and CSS to PDF, including Bootstrap 5, Tailwind CSS, or any contemporary web design, IronPDF provides browser-based rendering through its embedded Chromium engine. The choice depends on whether the project can accept CSS 2.1 constraints or requires modern web standards support.
Jacob Mellor is CTO at Iron Software and originally developed IronPDF. He has 25+ years of experience building developer tools.
References
- PDFsharp FAQ - HTML Conversion Support{:rel="nofollow"} - Official confirmation that PdfSharp does not support HTML conversion
- Can PDFSharp create Pdf file from a Html string in Net Core?{:rel="nofollow"} - Stack Overflow discussion on PdfSharp HTML limitations
- HtmlRenderer.PdfSharp NuGet Package{:rel="nofollow"} - Official package describing HTML 4.01 and CSS Level 2 support
- GitHub Issue #193 - Table Header Repetition{:rel="nofollow"} - Bug report on thead styling being ignored
- GitHub Issue #65 - External CSS{:rel="nofollow"} - Discussion on external stylesheet loading problems
- GitHub Issue #143 - Version Compatibility{:rel="nofollow"} - Report on PdfSharp version conflicts
- PdfSharp Forum - Letter-spacing CSS{:rel="nofollow"} - Discussion on CSS property support issues
- PdfSharp Forum - Convert HTML To PDF Help{:rel="nofollow"} - Forum thread on HTML conversion challenges
- HtmlRenderer.PdfSharp.NetStandard2 NuGet{:rel="nofollow"} - .NET Standard port package
- ArthurHub/HTML-Renderer GitHub Repository{:rel="nofollow"} - Source repository for HtmlRenderer library
For comprehensive IronPDF documentation including tutorials, API reference, and code examples, visit ironpdf.com.
Top comments (0)