If you've tried using iTextSharp for HTML-to-PDF conversion, you've probably experienced the pain: broken layouts, missing CSS, unsupported modern features, and verbose, complex APIs.
iTextSharp wasn't designed for HTML rendering. It's a low-level PDF manipulation library that happens to have an outdated HTML parser bolted on.
Here's why iTextSharp fails at HTML-to-PDF, and what to use instead in 2025.
Why iTextSharp Fails at HTML-to-PDF
1. Requires Paid Add-On (pdfHTML)
iTextSharp's core library doesn't support HTML at all. For HTML-to-PDF conversion, you need pdfHTML, a paid commercial add-on.
Pricing:
- iTextSharp Core (AGPL): "Free" but requires open-sourcing your app
- pdfHTML Add-On: Requires commercial license ($1,800+ per developer)
So "free" iTextSharp actually costs more than alternatives like IronPDF ($749).
2. Outdated HTML/CSS Support
pdfHTML's rendering engine is years behind modern web standards.
What doesn't work:
❌ Flexbox (Bootstrap 4/5 layouts break)
❌ CSS Grid (modern responsive layouts fail)
❌ CSS Variables (custom properties ignored)
❌ Modern selectors (:nth-child, :not, attribute selectors)
❌ JavaScript (no execution before rendering)
❌ Web fonts (Google Fonts often fail to load)
Example that breaks in iTextSharp:
<div style="display: flex; justify-content: space-between;">
<div>Left column</div>
<div>Right column</div>
</div>
iTextSharp result: Columns stack vertically instead of side-by-side (flexbox not supported).
IronPDF result: Perfect side-by-side layout (Chromium rendering).
3. Incredibly Verbose API
Simple HTML conversion requires dozens of lines of boilerplate code.
iTextSharp HTML to PDF:
using iText.Html2Pdf;
using iText.Kernel.Pdf;
using System.IO;
// Requires commercial pdfHTML add-on
var html = "<h1>Hello World</h1>";
var htmlStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(html));
using var pdfStream = new FileStream("output.pdf", FileMode.Create);
using var pdfWriter = new PdfWriter(pdfStream);
using var pdfDocument = new PdfDocument(pdfWriter);
HtmlConverter.ConvertToPdf(htmlStream, pdfDocument);
IronPDF equivalent:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-webgl-sites-to-pdf-in-csharp-ironpdf/)();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
80% less code, same result.
4. Bootstrap Layouts Break
Bootstrap relies heavily on flexbox (since Bootstrap 4). iTextSharp's pdfHTML doesn't support flexbox, so layouts break completely.
Bootstrap HTML:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
<div class="col">Column 3</div>
</div>
</div>
iTextSharp result: Three rows (stacked vertically) instead of three columns.
IronPDF result: Three side-by-side columns (Chromium understands Bootstrap).
5. JavaScript Doesn't Execute
If your HTML relies on JavaScript to populate content (charts, SPAs, dynamic data), iTextSharp renders an empty PDF.
HTML with JavaScript:
<div id="content">Loading...</div>
<script>
document.getElementById('content').innerHTML = '<h1>Loaded!</h1>';
</script>
iTextSharp result: PDF shows "Loading..." (JavaScript never executed).
IronPDF result: PDF shows "Loaded!" (Chromium executes JavaScript first).
6. Poor Documentation
iTextSharp's documentation is fragmented across:
- Stack Overflow (outdated answers)
- Official docs (often for Java version, not C#)
- GitHub issues (no official support)
Finding solutions requires:
- Searching multiple sources
- Trial and error
- Reading source code
IronPDF's documentation is comprehensive, C#-focused, and includes working code examples for every feature.
Better Alternative #1: IronPDF (Chromium-Based)
IronPDF uses Chromium rendering (same engine as Google Chrome), which means:
✅ Full HTML5/CSS3 support (flexbox, grid, variables)
✅ JavaScript execution (charts, SPAs, dynamic content)
✅ Bootstrap/Tailwind work perfectly
✅ Google Fonts and custom fonts load reliably
✅ Simpler API (3 lines vs. 20+ lines)
IronPDF HTML-to-PDF:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var html = @"
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
<div class='container'>
<div class='row'>
<div class='col'>Column 1</div>
<div class='col'>Column 2</div>
<div class='col'>Column 3</div>
</div>
</div>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("bootstrap.pdf");
Result: Perfect 3-column layout.
Pricing: $749 per developer (cheaper than iTextSharp + pdfHTML commercial license).
Better Alternative #2: PuppeteerSharp (Headless Chrome)
PuppeteerSharp is a .NET port of Google's Puppeteer (browser automation).
Pros:
- Free (Apache 2.0 license)
- Chromium-based (modern rendering)
- Supports JavaScript execution
Cons:
- Large (300MB+ Chromium binaries)
- Resource-intensive (spawns browser processes)
- Not a PDF library (it's a testing tool)
PuppeteerSharp HTML-to-PDF:
using PuppeteerSharp;
// Install via NuGet: Install-Package PuppeteerSharp
var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
var page = await browser.NewPageAsync();
await page.SetContentAsync("<h1>Hello World</h1>");
await page.PdfAsync("output.pdf");
await browser.CloseAsync();
Good for: Projects with $0 budget that can tolerate complexity.
Not good for: Production apps requiring simple deployment.
Better Alternative #3: Playwright for .NET
Playwright is Microsoft's browser automation library (similar to Puppeteer).
Pros:
- Free (Apache 2.0)
- Modern Chromium rendering
- Cross-browser support (Chromium, Firefox, WebKit)
Cons:
- Heavy (browser binaries)
- Complex deployment
- Not a PDF library (testing tool)
Playwright HTML-to-PDF:
using Microsoft.Playwright;
// Install via NuGet: Install-Package Microsoft.Playwright
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.SetContentAsync("<h1>Hello World</h1>");
await page.PdfAsync(new() { Path = "output.pdf" });
await browser.CloseAsync();
Good for: Teams already using Playwright for testing.
Not good for: Dedicated PDF generation.
Comparison: iTextSharp vs. Alternatives
| Feature | iTextSharp + pdfHTML | IronPDF | PuppeteerSharp | Playwright |
|---|---|---|---|---|
| HTML5/CSS3 Support | ❌ Limited | ✅ Full (Chromium) | ✅ Full | ✅ Full |
| Flexbox/Grid | ❌ No | ✅ Yes | ✅ Yes | ✅ Yes |
| JavaScript Execution | ❌ No | ✅ Yes | ✅ Yes | ✅ Yes |
| Bootstrap Layouts | ❌ Breaks | ✅ Works | ✅ Works | ✅ Works |
| API Simplicity | ❌ Verbose | ✅ Simple | ⚠️ Moderate | ⚠️ Moderate |
| Deployment Size | Small | Medium | Large (300MB+) | Large (300MB+) |
| Licensing | AGPL or $1,800+ | $749 | Free (Apache 2.0) | Free (Apache 2.0) |
| PDF Manipulation | ✅ Excellent | ✅ Yes | ❌ No | ❌ No |
Migration: iTextSharp to IronPDF
Before (iTextSharp)
using iText.Html2Pdf;
using iText.Kernel.Pdf;
// Requires commercial pdfHTML license
var htmlContent = "<h1>Invoice #12345</h1><p>Total: $500</p>";
var htmlStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlContent));
using var pdfStream = new FileStream("invoice.pdf", FileMode.Create);
using var pdfWriter = new PdfWriter(pdfStream);
using var pdfDocument = new PdfDocument(pdfWriter);
HtmlConverter.ConvertToPdf(htmlStream, pdfDocument);
After (IronPDF)
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var htmlContent = "<h1>Invoice #12345</h1><p>Total: $500</p>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("invoice.pdf");
Benefits:
- 70% less code
- Modern CSS support
- No stream management
- Clearer intent
Real-World Example: Invoice with Bootstrap
HTML template:
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col">
<h1>Invoice #12345</h1>
<p>Date: January 26, 2025</p>
</div>
<div class="col text-end">
<img src="logo.png" alt="Company Logo" width="150">
</div>
</div>
<table class="table table-striped mt-4">
<thead>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Consulting Services</td>
<td>10 hours</td>
<td>$150</td>
<td>$1,500</td>
</tr>
</tbody>
</table>
<div class="row mt-4">
<div class="col text-end">
<h3>Total: $1,500</h3>
</div>
</div>
</div>
</body>
</html>
iTextSharp result: Layout broken, columns stack, table formatting lost.
IronPDF result: Perfect professional invoice, exactly as designed.
Code:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("invoice-template.html");
pdf.SaveAs("invoice.pdf");
When to Use Each Alternative
Use IronPDF if:
- ✅ You need modern CSS/JavaScript support
- ✅ You're building commercial applications
- ✅ Simple APIs matter
- ✅ PDF manipulation features are valuable
- ✅ Budget allows $749 per developer
Use PuppeteerSharp/Playwright if:
- ✅ Budget is $0
- ✅ You're okay with deployment complexity
- ✅ You're already using them for testing
- ✅ You don't need PDF manipulation
Avoid iTextSharp if:
- ❌ You need HTML-to-PDF conversion (it's terrible at this)
- ❌ You use modern CSS frameworks (Bootstrap, Tailwind)
- ❌ You need JavaScript execution
- ❌ Simple APIs matter
Use iTextSharp only if:
- ✅ You need low-level PDF manipulation (not HTML conversion)
- ✅ You're doing programmatic PDF generation (no HTML)
- ✅ You need granular control over PDF structure
The Bottom Line
iTextSharp is terrible for HTML-to-PDF because:
- No HTML support in core library (requires paid add-on)
- Outdated CSS support (no flexbox, grid, modern features)
- No JavaScript execution (SPAs, charts fail)
- Verbose, complex API (20+ lines for simple conversions)
- Expensive ($1,800+ per developer with pdfHTML)
In 2025, better alternatives exist:
| Use Case | Best Choice | Why |
|---|---|---|
| Production HTML-to-PDF | IronPDF | Modern rendering, simple API, $749 |
| $0 budget | PuppeteerSharp | Free, Chromium-based, complex deployment |
| Already using testing tools | Playwright | Free, cross-browser, heavyweight |
| Low-level PDF manipulation | iTextSharp | Powerful, but NOT for HTML |
Stop using iTextSharp for HTML-to-PDF in 2025. It's outdated, expensive, and broken.
Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.
Top comments (0)