DEV Community

IronSoftware
IronSoftware

Posted on

Migrating from iTextSharp to IronPDF (.NET Guide)

If you're using iTextSharp (or iText 7) and hitting friction—complex API, AGPL licensing issues, poor HTML support, or steep learning curves—migrating to IronPDF can simplify your codebase and unlock modern features.

I've helped multiple teams migrate from iTextSharp to IronPDF. Here's a practical guide based on real migrations.

Why Migrate from iTextSharp to IronPDF?

1. AGPL Licensing Is a Blocker

iTextSharp's AGPL license requires you to open-source your application if you use the free version. For commercial SaaS products, this is a non-starter.

The commercial license costs $1,800+ per developer, significantly more than IronPDF's $749 starting price.

If you're building proprietary software, IronPDF eliminates licensing headaches.

2. HTML-to-PDF Support Is Poor in iTextSharp

iTextSharp's HTML rendering is outdated. It doesn't support modern CSS (flexbox, grid, CSS variables) or JavaScript execution.

iTextSharp HTML conversion (requires paid pdfHTML add-on):

using iText.Html2Pdf;
// Requires commercial license for pdfHTML add-on

HtmlConverter.ConvertToPdf(new FileInfo("input.html"), new FileInfo("output.pdf"));
Enter fullscreen mode Exit fullscreen mode

Even with pdfHTML, rendering fidelity is poor for modern web content.

IronPDF HTML conversion (built-in, no add-ons):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-html-string-to-pdf-in-csharp-ironpdf/)();
var pdf = renderer.RenderHtmlFileAsPdf("input.html");
pdf.SaveAs("output.pdf");
Enter fullscreen mode Exit fullscreen mode

IronPDF uses Chromium, so CSS3 and JavaScript work exactly like they do in Chrome.

3. iTextSharp's API Is Verbose and Complex

Simple tasks require dozens of lines of boilerplate code with iTextSharp.

Example: Adding a watermark

iTextSharp (30+ lines):

using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Font;
using iText.Kernel.Geom;
// Install via NuGet: Install-Package itext7

var reader = new PdfReader("input.pdf");
var writer = new PdfWriter("output.pdf");
var pdf = new PdfDocument(reader, writer);

var font = PdfFontFactory.CreateFont();
var pageCount = pdf.GetNumberOfPages();

for (int i = 1; i <= pageCount; i++)
{
    var page = pdf.GetPage(i);
    var pageSize = page.GetPageSize();
    var canvas = new PdfCanvas(page);

    canvas.SaveState();
    canvas.SetFontAndSize(font, 60);
    canvas.SetFillColorRgb(0.5f, 0.5f, 0.5f);

    var x = pageSize.GetWidth() / 2;
    var y = pageSize.GetHeight() / 2;
    canvas.ShowTextAligned("DRAFT", x, y, i, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 45);
    canvas.RestoreState();
}

pdf.Close();
Enter fullscreen mode Exit fullscreen mode

IronPDF (3 lines):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark("<h1 style='color: rgba(0,0,0,0.3);'>DRAFT</h1>", rotation: 45);
pdf.SaveAs("output.pdf");
Enter fullscreen mode Exit fullscreen mode

IronPDF reduces boilerplate by 90%, making code easier to read and maintain.

4. Better Performance for HTML Rendering

IronPDF excels at HTML rendering, generating PDFs faster than iTextSharp's pdfHTML add-on. It's also more memory-efficient, especially in resource-constrained environments.

Benchmark (100 HTML documents):

  • IronPDF: ~60 seconds
  • iTextSharp + pdfHTML: ~90 seconds (and requires commercial add-on)

5. Modern Features Out of the Box

IronPDF includes features that require add-ons or complex code in iTextSharp:

  • Native printing support: IronPDF supports direct PDF printing; iTextSharp requires third-party libraries
  • PDF/A compliance: Built-in with IronPDF; manual configuration in iTextSharp
  • Digital signatures: Simpler API in IronPDF
  • Form filling: Easier with IronPDF's high-level API

Key Differences Between iTextSharp and IronPDF

Feature iTextSharp IronPDF
HTML to PDF Poor (requires paid pdfHTML add-on) ⭐⭐⭐⭐⭐ Chromium-based, pixel-perfect
Modern CSS (Flexbox, Grid) ❌ Not supported ✅ Fully supported
JavaScript Execution ❌ Not supported ✅ Fully supported
API Complexity High (verbose, low-level) Low (high-level, concise)
Licensing AGPL or $1,800+/dev Commercial $749+/dev
Learning Curve Steep Gentle
Low-Level PDF Control ⭐⭐⭐⭐⭐ Granular ⚠️ Limited
Text Extraction Manual iteration, verbose ExtractAllText()
Printing Support ❌ Requires third-party libs ✅ Built-in

Migration Strategy: Step-by-Step

Step 1: Identify Your Use Cases

Categorize your iTextSharp usage:

  1. HTML-to-PDF conversion → Straightforward migration to IronPDF
  2. Programmatic PDF generation (invoices, reports) → Consider if IronPDF's HTML-based approach works for you
  3. PDF manipulation (merge, split, extract text) → IronPDF supports this, but API differs
  4. Low-level PDF editing (precise positioning, custom fonts) → May need to stay with iTextSharp for deep control

If 80%+ of your usage is HTML-to-PDF, migration is a slam dunk.

Step 2: Start with HTML-to-PDF Conversions

This is the easiest win. Replace iTextSharp's pdfHTML with IronPDF's Chromium rendering.

Before (iTextSharp):

using iText.Html2Pdf;
// Requires commercial pdfHTML add-on

var html = "<h1>Invoice</h1><p>Total: $500</p>";
HtmlConverter.ConvertToPdf(html, new FileStream("invoice.pdf", FileMode.Create));
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var html = "<h1>Invoice</h1><p>Total: $500</p>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");
Enter fullscreen mode Exit fullscreen mode

Benefits:

  • Modern CSS/JavaScript support
  • Simpler code
  • No paid add-on required

Step 3: Migrate Text Extraction

iTextSharp requires manual iteration and verbose code. IronPDF simplifies this.

Before (iTextSharp):

using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
// Install via NuGet: Install-Package itext7

var reader = new PdfReader("document.pdf");
var pdf = new PdfDocument(reader);

var text = new StringBuilder();
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
    var page = pdf.GetPage(i);
    var strategy = new SimpleTextExtractionStrategy();
    text.Append(PdfTextExtractor.GetTextFromPage(page, strategy));
}

pdf.Close();
Console.WriteLine(text.ToString());
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("document.pdf");
var text = pdf.ExtractAllText();
Console.WriteLine(text);
Enter fullscreen mode Exit fullscreen mode

90% less code, same result.

Step 4: Migrate Form Filling

Before (iTextSharp):

using iText.Kernel.Pdf;
using iText.Forms;
using iText.Forms.Fields;
// Install via NuGet: Install-Package itext7

var reader = new PdfReader("form-template.pdf");
var writer = new PdfWriter("filled-form.pdf");
var pdf = new PdfDocument(reader, writer);

var form = PdfAcroForm.GetAcroForm(pdf, true);
var fields = form.GetFormFields();
fields["name"].SetValue("John Doe");
fields["email"].SetValue("john@example.com");

pdf.Close();
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("form-template.pdf");
pdf.Form.SetFieldValue("name", "John Doe");
pdf.Form.SetFieldValue("email", "john@example.com");
pdf.SaveAs("filled-form.pdf");
Enter fullscreen mode Exit fullscreen mode

Cleaner, more intuitive API.

Step 5: Migrate PDF Merging

Before (iTextSharp):

using iText.Kernel.Pdf;
using iText.Kernel.Utils;
// Install via NuGet: Install-Package itext7

var writer = new PdfWriter("merged.pdf");
var pdf = new PdfDocument(writer);
var merger = new PdfMerger(pdf);

var pdf1 = new PdfDocument(new PdfReader("doc1.pdf"));
var pdf2 = new PdfDocument(new PdfReader("doc2.pdf"));

merger.Merge(pdf1, 1, pdf1.GetNumberOfPages());
merger.Merge(pdf2, 1, pdf2.GetNumberOfPages());

pdf1.Close();
pdf2.Close();
pdf.Close();
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf1 = PdfDocument.FromFile("doc1.pdf");
var pdf2 = PdfDocument.FromFile("doc2.pdf");

var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
Enter fullscreen mode Exit fullscreen mode

50% less code, no manual lifecycle management.

Step 6: Migrate Digital Signatures

Before (iTextSharp):

using iText.Kernel.Pdf;
using iText.Signatures;
using Org.BouncyCastle.Pkcs;
// Install via NuGet: Install-Package itext7 and BouncyCastle

var reader = new PdfReader("document.pdf");
var writer = new PdfWriter("signed.pdf");

var signer = new PdfSigner(reader, writer, new StampingProperties());

var pk12 = new Pkcs12Store(new FileStream("cert.pfx", FileMode.Open), "password".ToCharArray());
var alias = pk12.Aliases.Cast<string>().First();
var privateKey = pk12.GetKey(alias).Key;

var chain = pk12.GetCertificateChain(alias);
var externalSignature = new PrivateKeySignature(privateKey, "SHA-256");

signer.SignDetached(externalSignature, chain, null, null, null, 0, PdfSigner.CryptoStandard.CMS);
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
using IronPdf.Signing;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("document.pdf");

var signature = new PdfSignature("cert.pfx", "password");
signature.SigningContact = "legal@company.com";
signature.SigningReason = "Contract Approval";

pdf.Sign(signature);
pdf.SaveAs("signed.pdf");
Enter fullscreen mode Exit fullscreen mode

Drastically simpler—no BouncyCastle integration required.

Step 7: Migrate Watermarking

Before (iTextSharp):

// 30+ lines of code (shown earlier in "Why Migrate" section)
Enter fullscreen mode Exit fullscreen mode

After (IronPDF):

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = PdfDocument.FromFile("document.pdf");
pdf.ApplyWatermark("<h1 style='color: rgba(255,0,0,0.3);'>CONFIDENTIAL</h1>", rotation: 45);
pdf.SaveAs("watermarked.pdf");
Enter fullscreen mode Exit fullscreen mode

One method call vs. 30+ lines.

What If I Need Low-Level PDF Control?

iTextSharp's strength is granular control over PDF structure. If you're doing advanced PDF editing (custom font embedding, precise positioning, PDF compliance tweaking), iTextSharp may still be necessary.

IronPDF abstracts low-level details, which is great for 90% of use cases but limits you when you need PDF internals.

Options:

  1. Hybrid approach: Use IronPDF for HTML-to-PDF, keep iTextSharp for low-level tasks
  2. Evaluate alternatives: Aspose.PDF offers low-level control with a more modern API (but costs more)
  3. Stay with iTextSharp: If low-level control is critical and budget allows for commercial licensing

Licensing Migration

iTextSharp AGPL gotcha:

If you're using iTextSharp's free AGPL version, you're required to open-source your application. Most companies don't realize this until legal review.

IronPDF licensing:

  • Starting price: $749 per developer
  • No AGPL restrictions: Your source code stays private
  • Deployment licenses: One license covers all instances of a deployed application

Cost comparison:

  • iTextSharp commercial: $1,800+/developer
  • IronPDF: $749+/developer

IronPDF saves $1,050+ per developer while offering better HTML rendering.

Performance Considerations After Migration

IronPDF's first render takes ~2.8 seconds (Chromium initialization). Subsequent renders are <1 second.

Optimization tip:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

// Reuse renderer to avoid re-initialization
public class PdfService
{
    private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();

    public PdfDocument GeneratePdf(string html)
    {
        return _renderer.RenderHtmlAsPdf(html);
    }
}
Enter fullscreen mode Exit fullscreen mode

Reusing the renderer gives you 5-20x speedup for batch operations.

Common Migration Challenges

Challenge 1: Complex Layout Logic

If you're using iTextSharp's low-level API to position text/images precisely, IronPDF's HTML-based approach requires rethinking.

Solution:

Convert your layout logic to HTML/CSS templates. Use CSS Grid or Flexbox for positioning.

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var html = @"
<style>
    .invoice { display: grid; grid-template-columns: 1fr 1fr; }
    .left { text-align: left; }
    .right { text-align: right; }
</style>
<div class='invoice'>
    <div class='left'>Company Name</div>
    <div class='right'>Invoice #12345</div>
</div>";

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");
Enter fullscreen mode Exit fullscreen mode

Challenge 2: Missing Features

IronPDF doesn't support every iTextSharp feature. If you're using obscure PDF features (custom rendering modes, PDF layers, etc.), verify support before migrating.

Solution:

  • Test a proof-of-concept with IronPDF
  • Contact IronPDF support to verify feature availability
  • Consider hybrid approach (IronPDF + iTextSharp for edge cases)

Challenge 3: Learning New API

Teams familiar with iTextSharp need to learn IronPDF's API.

Solution:

  • IronPDF's learning curve is gentler (high-level API)
  • Most developers are productive within 1-2 days
  • Official docs cover common migration scenarios

Migration Checklist

Audit current iTextSharp usage (HTML conversion, text extraction, forms, signatures, etc.)

Identify low-level PDF tasks that might require staying with iTextSharp

Install IronPDF via NuGet and build proof-of-concept

Migrate HTML-to-PDF conversions first (biggest win, easiest migration)

Migrate text extraction (simple API swap)

Migrate form filling (cleaner API)

Migrate merging/splitting (fewer lines of code)

Migrate digital signatures (no BouncyCastle required)

Performance test with real workloads

License compliance review (ensure IronPDF license covers deployment)

Train team on IronPDF API

Deprecate iTextSharp once migration is complete

Should You Migrate?

Migrate to IronPDF if:

  • 80%+ of your usage is HTML-to-PDF conversion
  • You're tired of iTextSharp's verbose API
  • AGPL licensing is blocking deployment
  • You need modern CSS/JavaScript support
  • You want simpler code and faster development

Stay with iTextSharp if:

  • You need granular, low-level PDF control
  • Your codebase is heavily invested in iTextSharp's API
  • You're already paying for commercial iTextSharp licenses
  • HTML rendering is not your primary use case

For most teams, IronPDF simplifies PDF generation, reduces code complexity, and costs less than iTextSharp's commercial license. The migration is worth the effort.


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)