Skip to footer content
PRODUCT COMPARISONS

Create PDF in ASP.NET: iTextSharp vs IronPDF

Question: Can you create PDFs in ASP.NET with iTextSharp, and is there a better alternative? Yes -- iTextSharp is a long-established .NET PDF library, but IronPDF offers a modern HTML-to-PDF approach that eliminates the need to learn low-level PDF document structures. This guide compares both libraries with working code examples so you can choose the right tool for your project.

What Are the Key Differences Between iTextSharp and IronPDF?

iTextSharp is a .NET port of the Java iText library, offering programmatic PDF creation through its document class and low-level PDF content manipulation. While powerful, using iTextSharp requires understanding PDF document structure, working with document objects, and manually positioning elements using coordinates and page size specifications. The API is verbose by necessity -- the library exposes the full complexity of the PDF specification, which means there is a lot to learn before producing polished output.

IronPDF takes a different approach, focusing on HTML-to-PDF conversion using a Chrome rendering engine. Developers can generate PDF files using familiar HTML and CSS, making PDF creation as straightforward as designing a web page. IronPDF handles the PDF generation logic behind the scenes, allowing you to produce documents with modern styling and JavaScript support. Because the rendering pipeline is powered by Chromium, any layout that works in a modern browser will translate faithfully to the PDF output -- including flexbox, grid, web fonts, and JavaScript-generated content.

The practical consequence of this architectural difference is that iTextSharp rewards developers who want fine-grained, coordinate-level control over every byte in a PDF file, while IronPDF rewards developers who want to produce visually polished documents quickly using skills they already have. For most web application scenarios -- invoices, reports, order confirmations, and data exports -- the HTML approach is faster to build and easier to maintain.

iTextSharp vs IronPDF: Feature Comparison
Feature iTextSharp IronPDF
HTML to PDF Limited (via XMLWorker add-on) Full Chrome-engine rendering
CSS Support Partial Full CSS3 support
JavaScript Support None Yes (via Chrome engine)
Licensing AGPL (commercial license required) Commercial, royalty-free
Learning Curve Steep (PDF API knowledge needed) Low (HTML/CSS sufficient)
NuGet Install Install-Package iTextSharp Install-Package IronPdf
.NET Compatibility .NET Framework, .NET Core .NET 8, .NET 9, .NET 10, Framework

How Do You Install These Libraries in a .NET Project?

Installing either library starts with the NuGet Package Manager. For iTextSharp, note that newer iText versions operate under the AGPL license, which requires either open-sourcing your application or purchasing a commercial license:

# Install iTextSharp via Package Manager Console
Install-Package iTextSharp
# Install iTextSharp via Package Manager Console
Install-Package iTextSharp
SHELL

For IronPDF, you can install it through the NuGet Package Manager Console, the .NET CLI, or by searching directly in Visual Studio's NuGet UI:

Install-Package IronPdf

After installation, IronPDF is ready to use with a single using statement. No additional configuration is required for basic PDF generation. For advanced scenarios -- such as setting a license key, configuring rendering options, or generating PDFs in a cloud environment -- see the IronPDF documentation. IronPDF supports Linux, macOS, and Windows deployments, including containerized environments running in Docker or Kubernetes, which makes it well-suited for modern cloud-native ASP.NET applications.

How Do You Create a Basic PDF Document with Each Library?

The clearest way to understand the API difference is to create a simple "Hello World" PDF with both libraries side by side.

Generating a PDF with iTextSharp

With iTextSharp, you work directly with the Document class and PdfWriter:

using iTextSharp.text;
using iTextSharp.text.pdf;

var memoryStream = new MemoryStream();
Document pdfDoc = new Document(PageSize.A4, 25, 25, 25, 15);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
pdfDoc.Open();

var paragraph = new Paragraph("Hello World - PDF Document");
paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 16);
pdfDoc.Add(paragraph);
pdfDoc.Add(new Paragraph("Creating PDF documents with iTextSharp"));

pdfDoc.Close();

// Return as a downloadable file
var pdfBytes = memoryStream.ToArray();
using iTextSharp.text;
using iTextSharp.text.pdf;

var memoryStream = new MemoryStream();
Document pdfDoc = new Document(PageSize.A4, 25, 25, 25, 15);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
pdfDoc.Open();

var paragraph = new Paragraph("Hello World - PDF Document");
paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 16);
pdfDoc.Add(paragraph);
pdfDoc.Add(new Paragraph("Creating PDF documents with iTextSharp"));

pdfDoc.Close();

// Return as a downloadable file
var pdfBytes = memoryStream.ToArray();
$vbLabelText   $csharpLabel

This requires knowing how Document, PdfWriter, Paragraph, and FontFactory interact -- a non-trivial learning investment for developers new to PDF generation.

Generating a PDF with IronPDF

With IronPDF, the equivalent task uses familiar HTML:

using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
    <h1>Hello World - PDF Document</h1>
    <p>Creating PDFs with IronPDF is straightforward!</p>
");

var pdfBytes = pdf.BinaryData;
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(@"
    <h1>Hello World - PDF Document</h1>
    <p>Creating PDFs with IronPDF is straightforward!</p>
");

var pdfBytes = pdf.BinaryData;
$vbLabelText   $csharpLabel

IronPDF's approach lets you write HTML directly, eliminating the need to work with low-level PDF elements. The ChromePdfRenderer class handles all rendering internally using a Chromium-based engine, ensuring pixel-accurate output.

How Do You Create Styled PDFs with Images and CSS?

Styled documents reveal the most significant gap between the two libraries. When generating invoices, reports, or branded documents, CSS-based styling in IronPDF dramatically reduces the amount of code required.

Invoice Generation with IronPDF

using IronPdf;

var html = @"
    <style>
        body { font-family: Arial, sans-serif; margin: 0; }
        .invoice-header { background: #4CAF50; color: white; padding: 20px; }
        .invoice-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        .invoice-table th, .invoice-table td {
            border: 1px solid #ddd; padding: 8px; text-align: left;
        }
        .invoice-table th { background-color: #f2f2f2; }
        .total { font-size: 18px; font-weight: bold; margin-top: 16px; }
    </style>
    <div class='invoice-header'>
        <h1>Invoice #2024-001</h1>
        <p>Due: March 15, 2024</p>
    </div>
    <table class='invoice-table'>
        <tr><th>Item</th><th>Quantity</th><th>Unit Price</th><th>Total</th></tr>
        <tr><td>PDF License</td><td>1</td><td>$599</td><td>$599</td></tr>
        <tr><td>Support Package</td><td>1</td><td>$199</td><td>$199</td></tr>
    </table>
    <p class='total'>Grand Total: $798</p>
";

var renderer = new ChromePdfRenderer();
var pdfDocument = renderer.RenderHtmlAsPdf(html);
var pdfBytes = pdfDocument.BinaryData;
using IronPdf;

var html = @"
    <style>
        body { font-family: Arial, sans-serif; margin: 0; }
        .invoice-header { background: #4CAF50; color: white; padding: 20px; }
        .invoice-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        .invoice-table th, .invoice-table td {
            border: 1px solid #ddd; padding: 8px; text-align: left;
        }
        .invoice-table th { background-color: #f2f2f2; }
        .total { font-size: 18px; font-weight: bold; margin-top: 16px; }
    </style>
    <div class='invoice-header'>
        <h1>Invoice #2024-001</h1>
        <p>Due: March 15, 2024</p>
    </div>
    <table class='invoice-table'>
        <tr><th>Item</th><th>Quantity</th><th>Unit Price</th><th>Total</th></tr>
        <tr><td>PDF License</td><td>1</td><td>$599</td><td>$599</td></tr>
        <tr><td>Support Package</td><td>1</td><td>$199</td><td>$199</td></tr>
    </table>
    <p class='total'>Grand Total: $798</p>
";

var renderer = new ChromePdfRenderer();
var pdfDocument = renderer.RenderHtmlAsPdf(html);
var pdfBytes = pdfDocument.BinaryData;
$vbLabelText   $csharpLabel

Invoice Generation with iTextSharp

Achieving similar output with iTextSharp requires constructing every visual element programmatically:

using iTextSharp.text;
using iTextSharp.text.pdf;

var output = new MemoryStream();
var document = new Document(PageSize.A4);
PdfWriter.GetInstance(document, output);
document.Open();

// Header -- manual font and color setup
var titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20,
    new BaseColor(255, 255, 255));
var headerParagraph = new Paragraph("Invoice #2024-001", titleFont);
document.Add(headerParagraph);

// Table -- each cell must be created individually
PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 100;

string[] headers = { "Item", "Quantity", "Unit Price", "Total" };
foreach (var h in headers)
{
    var cell = new PdfPCell(new Phrase(h,
        FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10)));
    cell.BackgroundColor = new BaseColor(242, 242, 242);
    table.AddCell(cell);
}

table.AddCell("PDF License");
table.AddCell("1");
table.AddCell("$599");
table.AddCell("$599");
document.Add(table);

var totalFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14);
document.Add(new Paragraph("Grand Total: $798", totalFont));
document.Close();
using iTextSharp.text;
using iTextSharp.text.pdf;

var output = new MemoryStream();
var document = new Document(PageSize.A4);
PdfWriter.GetInstance(document, output);
document.Open();

// Header -- manual font and color setup
var titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20,
    new BaseColor(255, 255, 255));
var headerParagraph = new Paragraph("Invoice #2024-001", titleFont);
document.Add(headerParagraph);

// Table -- each cell must be created individually
PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 100;

string[] headers = { "Item", "Quantity", "Unit Price", "Total" };
foreach (var h in headers)
{
    var cell = new PdfPCell(new Phrase(h,
        FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10)));
    cell.BackgroundColor = new BaseColor(242, 242, 242);
    table.AddCell(cell);
}

table.AddCell("PDF License");
table.AddCell("1");
table.AddCell("$599");
table.AddCell("$599");
document.Add(table);

var totalFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14);
document.Add(new Paragraph("Grand Total: $798", totalFont));
document.Close();
$vbLabelText   $csharpLabel

The difference is clear: IronPDF handles CSS, modern HTML, and JavaScript, while iTextSharp requires manual creation of each element, font specification, and cell-by-cell table construction. For document-heavy applications generating dozens of distinct templates, this difference in code volume compounds significantly over time.

How Do You Handle Server-Side PDF Generation in ASP.NET?

Both libraries support server-side PDF generation for ASP.NET applications. The pattern for returning a PDF as a downloadable file response is similar regardless of which library generates the bytes. The key considerations for production use are memory management, thread safety, and response configuration. Both libraries use in-memory streams, so you should ensure you are not holding large PDFs in memory longer than necessary. IronPDF's ChromePdfRenderer is designed to be instantiated per request, so there is no shared state to worry about between concurrent requests.

ASP.NET Core Controller Action with IronPDF

using IronPdf;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
    [HttpGet("invoice/{id}")]
    public IActionResult GenerateInvoice(int id)
    {
        var html = BuildInvoiceHtml(id); // your HTML template

        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
        renderer.RenderingOptions.MarginTop = 20;
        renderer.RenderingOptions.MarginBottom = 20;

        var pdf = renderer.RenderHtmlAsPdf(html);

        return File(pdf.BinaryData, "application/pdf", $"invoice-{id}.pdf");
    }

    private static string BuildInvoiceHtml(int id)
    {
        return $"<h1>Invoice #{id}</h1><p>Generated on {DateTime.UtcNow:yyyy-MM-dd}</p>";
    }
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
    [HttpGet("invoice/{id}")]
    public IActionResult GenerateInvoice(int id)
    {
        var html = BuildInvoiceHtml(id); // your HTML template

        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
        renderer.RenderingOptions.MarginTop = 20;
        renderer.RenderingOptions.MarginBottom = 20;

        var pdf = renderer.RenderHtmlAsPdf(html);

        return File(pdf.BinaryData, "application/pdf", $"invoice-{id}.pdf");
    }

    private static string BuildInvoiceHtml(int id)
    {
        return $"<h1>Invoice #{id}</h1><p>Generated on {DateTime.UtcNow:yyyy-MM-dd}</p>";
    }
}
$vbLabelText   $csharpLabel

For ASP.NET MVC (non-Core) projects, return a FileResult in the same way. IronPDF also supports generating PDFs from URLs, which is helpful when converting existing web pages rather than constructing HTML strings.

You can also add headers and footers, apply digital signatures, set password protection, or merge multiple PDFs using IronPDF's document editing APIs -- all from the same package.

How Do You Migrate from iTextSharp to IronPDF?

Migrating an existing iTextSharp project to IronPDF follows a straightforward pattern:

  1. Replace document model code with HTML templates. Instead of constructing Paragraph, PdfPTable, and PdfPCell objects, build an HTML string or load an HTML file. Your existing CSS stylesheets and Razor partial views can be reused directly.
  2. Swap the rendering call. Replace PdfWriter.GetInstance(doc, stream) with new ChromePdfRenderer().RenderHtmlAsPdf(html).
  3. Update the byte extraction. Replace memoryStream.ToArray() with pdf.BinaryData.
  4. Transfer advanced settings. iTextSharp features like page margins, encryption, and document metadata have direct equivalents in IronPDF's RenderingOptions and PdfDocument APIs.
  5. Validate output fidelity. Run both outputs side-by-side on representative documents. IronPDF typically produces better visual results because it uses a full browser rendering engine rather than a PDF-native layout engine.

For teams with existing HTML templates (from email generators, Razor views, or report builders), migration can often be completed in hours rather than days. IronPDF can render Razor views directly to PDF within ASP.NET Core, which further accelerates migration. Teams that have invested in CSS-based document design -- for example, using print stylesheets to control page breaks and margins -- will find those skills transfer directly to IronPDF.

Review the IronPDF migration guide for detailed patterns covering encryption, stamping, and other advanced iTextSharp features.

Which Library Should You Choose?

For developers starting new projects or migrating from iTextSharp, the following factors apply:

Licensing: iTextSharp uses AGPL licensing for its newer versions, which requires either open-sourcing your application or purchasing a commercial license from iText Group. IronPDF offers straightforward commercial licensing with no open-source obligations. If your project is closed-source or commercial, this distinction alone may determine your choice.

Learning Curve: IronPDF's HTML-based approach means less time learning PDF-specific APIs. If your team knows HTML and CSS, PDF generation with IronPDF starts immediately. There is no need to study PDF coordinate systems, glyph encoding, or font embedding -- IronPDF handles all of that transparently.

Feature Coverage: IronPDF supports PDF/A compliance, form filling, watermarking, , and more -- all from a single NuGet package. Advanced features like digital signatures and PDF merging are also included without additional dependencies.

Migration Path: Moving from iTextSharp to IronPDF involves replacing document-manipulation code with HTML templates and updating the rendering call. The output quality is typically higher because IronPDF uses a full browser engine, and the resulting code is significantly shorter and easier to maintain.

For background on how PDF rendering engines work and what differentiates them, Mozilla's documentation on PDFs and Adobe's PDF specification resources provide useful context. The iText Group official site describes the AGPL terms in detail.

What Are Your Next Steps?

To get started with IronPDF in your ASP.NET project:

  1. Install the NuGet package: Install-Package IronPdf
  2. Add using IronPdf; to your file
  3. Create a ChromePdfRenderer and call RenderHtmlAsPdf() with your HTML
  4. Return pdf.BinaryData as a FileResult from your controller

Explore these resources to go further:

Please noteiTextSharp is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by iTextSharp. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.

Frequently Asked Questions

What are the main differences between iTextSharp and IronPDF for ASP.NET PDF generation?

The main differences include ease of use, licensing models, and rendering approach. IronPDF uses an HTML-to-PDF model powered by a Chrome engine, making it straightforward to produce styled documents. iTextSharp uses a low-level PDF document API that requires learning PDF-specific constructs. IronPDF also uses commercial licensing with no open-source obligations, while iTextSharp newer versions use AGPL.

Can IronPDF convert HTML to PDF in ASP.NET applications?

Yes, IronPDF can convert HTML to PDF in ASP.NET applications. It allows developers to render web pages, HTML strings, or HTML files directly to PDF with high fidelity using a Chromium-based rendering engine.

Is it possible to switch from iTextSharp to IronPDF?

Yes, switching from iTextSharp to IronPDF is straightforward. The migration involves replacing document-model code with HTML templates and updating the rendering call. Teams with existing HTML or Razor templates can often migrate in hours.

Does IronPDF support generating PDFs from ASP.NET web applications?

IronPDF fully supports generating PDFs from ASP.NET and ASP.NET Core web applications. It integrates into existing projects via NuGet and supports controller action patterns for returning PDF files.

What types of documents can be created using IronPDF?

Using IronPDF, you can create invoices, reports, data exports, and any document representable as HTML. It supports PDF/A compliance, form filling, digital signatures, watermarking, and barcode generation.

How does IronPDF handle licensing compared to iTextSharp?

IronPDF offers commercial licensing with no AGPL obligations, making it suitable for closed-source applications. iTextSharp newer versions use AGPL, which requires commercial licenses for proprietary software.

Are there code examples available for using IronPDF in ASP.NET?

Yes, IronPDF provides extensive code examples and documentation covering HTML to PDF conversion, URL rendering, ASP.NET Core controller patterns, and advanced features like headers, footers, and digital signatures.

Why should you consider using IronPDF over iTextSharp?

You should consider IronPDF if you want to produce styled documents using HTML and CSS, avoid the AGPL licensing requirements of newer iTextSharp versions, or reduce the amount of PDF-specific code your team needs to maintain.

Does IronPDF work in cloud and containerized environments?

Yes, IronPDF supports Linux, macOS, and Windows deployments, including Docker and Kubernetes containerized environments, making it suitable for modern cloud-native ASP.NET applications.

Is IronPDF suitable for enterprise-level ASP.NET projects?

Yes, IronPDF is suitable for enterprise ASP.NET projects. It provides reliable performance, PDF/A compliance, digital signature support, and scalability for high-volume document generation scenarios.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More