MigraDoc vs IronPDF: Technical Comparison Guide
When .NET developers need to generate PDF documents, they face two main approaches: building documents programmatically with libraries like MigraDoc, or using HTML-based rendering with tools like IronPDF. This comparison looks at both libraries across key technical aspects to assist developers, architects, and technical decision-makers in choosing the right method for their PDF generation workflows.
What Is MigraDoc?
MigraDoc is an open-source document object model built on top of PDFSharp, distributed under the MIT license. The library provides a high-level abstraction layer that uses word-processing concepts like Document, Section, Paragraph, Table, and Chart to create structured documents programmatically.
MigraDoc's approach requires developers to construct documents element by element through code. Each piece of content—headings, paragraphs, tables, images—must be explicitly created and configured using MigraDoc's proprietary API. The library then renders this document structure to PDF format using the PdfDocumentRenderer class.
This programmatic model makes MigraDoc particularly suited for generating structured reports, invoices, or documents that require consistent formatting across multiple pages. However, the approach requires learning MigraDoc's specific document model rather than using existing web development skills.
What Is IronPDF?
IronPDF is a commercial .NET library that converts HTML, CSS, and JavaScript into PDF documents using an embedded Chromium rendering engine. Rather than constructing documents programmatically, developers create content using familiar web technologies and let IronPDF handle the conversion.
The ChromePdfRenderer class serves as the primary interface for conversions. Developers pass HTML strings, files, or URLs to rendering methods, and IronPDF produces PDF documents with full fidelity to the original web content—including CSS styling, web fonts, and JavaScript-generated content.
This HTML-based approach allows teams to use existing web development skills and design tools, potentially sharing templates between web applications and PDF output.
Document Creation Paradigm Comparison
The main difference between MigraDoc and IronPDF lies in how developers define document content. This architectural distinction affects code complexity, learning curve, and styling flexibility.
| Feature | MigraDoc | IronPDF |
|---|---|---|
| Content Definition | Programmatic (Document/Section/Paragraph) | HTML/CSS |
| Learning Curve | Steep (proprietary DOM) | Easy (web skills) |
| Styling | Limited properties | Full CSS3 |
| JavaScript Support | None | Full Chromium execution |
| Tables | Manual column/row definition | HTML <table> with CSS |
| Charts | Basic MigraDoc charts | Any JavaScript charting library |
| Images | Manual sizing/positioning | Standard HTML <img> |
| Responsive Layouts | Not supported | Flexbox, Grid |
| License | Open Source (MIT) | Commercial |
MigraDoc requires developers to master its proprietary document model. Each element type has specific APIs for creation and configuration. IronPDF developers use HTML elements and CSS properties they likely already know from web development.
HTML to PDF: A Fundamental Difference
One of the most significant distinctions between these libraries is HTML support. MigraDoc does not support HTML directly—developers must manually create document structure using the API.
MigraDoc approach (no HTML support):
// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.Diagnostics;
class Program
{
static void Main()
{
// MigraDoc doesn't support HTML directly
// Must manually create document structure
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AddFormattedText("Hello World", TextFormat.Bold);
paragraph.Format.Font.Size = 16;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("output.pdf");
}
}// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.Diagnostics;
class Program
{
static void Main()
{
// MigraDoc doesn't support HTML directly
// Must manually create document structure
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AddFormattedText("Hello World", TextFormat.Bold);
paragraph.Format.Font.Size = 16;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("output.pdf");
}
}IronPDF approach (native HTML support):
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf.SaveAs("output.pdf");
}
}The code comparison reveals the fundamental paradigm difference. MigraDoc requires creating a Document, adding a Section, adding a Paragraph, then using AddFormattedText() with explicit formatting parameters. IronPDF accepts the HTML directly and renders it with a single method call.
For teams with existing HTML templates, email designs, or web content that needs PDF conversion, MigraDoc would require rebuilding those designs programmatically. IronPDF's HTML to PDF conversion allows direct reuse of existing web content.
Creating Tables in PDFs
Tables represent a common requirement in business documents like invoices, reports, and data exports. The implementation complexity differs significantly between the two libraries.
MigraDoc table creation:
// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
class Program
{
static void Main()
{
Document document = new Document();
Section section = document.AddSection();
Table table = section.AddTable();
table.Borders.Width = 0.75;
Column column1 = table.AddColumn("3cm");
Column column2 = table.AddColumn("3cm");
Row row1 = table.AddRow();
row1.Cells[0].AddParagraph("Name");
row1.Cells[1].AddParagraph("Age");
Row row2 = table.AddRow();
row2.Cells[0].AddParagraph("John");
row2.Cells[1].AddParagraph("30");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("table.pdf");
}
}// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
class Program
{
static void Main()
{
Document document = new Document();
Section section = document.AddSection();
Table table = section.AddTable();
table.Borders.Width = 0.75;
Column column1 = table.AddColumn("3cm");
Column column2 = table.AddColumn("3cm");
Row row1 = table.AddRow();
row1.Cells[0].AddParagraph("Name");
row1.Cells[1].AddParagraph("Age");
Row row2 = table.AddRow();
row2.Cells[0].AddParagraph("John");
row2.Cells[1].AddParagraph("30");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("table.pdf");
}
}IronPDF table creation:
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlTable = @"
<table border='1'>
<tr><th>Name</th><th>Age</th></tr>
<tr><td>John</td><td>30</td></tr>
</table>";
var pdf = renderer.RenderHtmlAsPdf(htmlTable);
pdf.SaveAs("table.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
string htmlTable = @"
<table border='1'>
<tr><th>Name</th><th>Age</th></tr>
<tr><td>John</td><td>30</td></tr>
</table>";
var pdf = renderer.RenderHtmlAsPdf(htmlTable);
pdf.SaveAs("table.pdf");
}
}MigraDoc requires explicit creation of the table structure: adding columns with specific widths, creating rows, accessing cells by index, and adding paragraphs to each cell. This approach spans 20+ lines for a simple two-column, two-row table.
IronPDF uses standard HTML table syntax that web developers already know. CSS can be applied for advanced styling including borders, backgrounds, cell padding, and responsive layouts. The table formatting capabilities extend to any CSS styling supported by modern browsers.
Headers and Footers
Professional documents typically require headers and footers with page numbers, dates, or company branding. Both libraries support this functionality with different approaches.
MigraDoc headers and footers:
// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
class Program
{
static void Main()
{
Document document = new Document();
Section section = document.AddSection();
// Add header
Paragraph headerPara = section.Headers.Primary.AddParagraph();
headerPara.AddText("Document Header");
headerPara.Format.Font.Size = 12;
headerPara.Format.Alignment = ParagraphAlignment.Center;
// Add footer
Paragraph footerPara = section.Footers.Primary.AddParagraph();
footerPara.AddText("Page ");
footerPara.AddPageField();
footerPara.Format.Alignment = ParagraphAlignment.Center;
// Add content
section.AddParagraph("Main content of the document");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("header-footer.pdf");
}
}// NuGet: Install-Package PdfSharp-MigraDoc-GDI
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
class Program
{
static void Main()
{
Document document = new Document();
Section section = document.AddSection();
// Add header
Paragraph headerPara = section.Headers.Primary.AddParagraph();
headerPara.AddText("Document Header");
headerPara.Format.Font.Size = 12;
headerPara.Format.Alignment = ParagraphAlignment.Center;
// Add footer
Paragraph footerPara = section.Footers.Primary.AddParagraph();
footerPara.AddText("Page ");
footerPara.AddPageField();
footerPara.Format.Alignment = ParagraphAlignment.Center;
// Add content
section.AddParagraph("Main content of the document");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("header-footer.pdf");
}
}IronPDF headers and footers:
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Main content of the document</h1>");
pdf.AddTextHeader("Document Header");
pdf.AddTextFooter("Page {page}");
pdf.SaveAs("header-footer.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Main content of the document</h1>");
pdf.AddTextHeader("Document Header");
pdf.AddTextFooter("Page {page}");
pdf.SaveAs("header-footer.pdf");
}
}MigraDoc requires accessing the Headers.Primary and Footers.Primary collections on the section, creating paragraphs within them, and using special methods like AddPageField() to insert page numbers.
IronPDF provides convenient methods like AddTextHeader() and AddTextFooter() that can be called on the PDF document after rendering. The {page} placeholder automatically inserts the current page number. IronPDF also supports HTML-based headers and footers for complex designs through the RenderingOptions.HtmlHeader and RenderingOptions.HtmlFooter properties.
Placeholder Syntax Comparison
When using dynamic content in headers and footers, the syntax differs:
| MigraDoc Method | IronPDF Placeholder | Purpose |
|---|---|---|
AddPageField() | {page} | Current page number |
AddNumPagesField() | {total-pages} | Total page count |
AddDateField() | {date} | Current date |
API Design Comparison
The API design philosophy reflects the underlying document creation paradigms.
Class Mappings
| MigraDoc Class | IronPDF Equivalent |
|---|---|
Document | ChromePdfRenderer |
Section | HTML <body> or <div> |
Paragraph | HTML <p>, <h1>, etc. |
FormattedText | HTML <span>, <strong>, etc. |
Table | HTML <table> |
Row | HTML <tr> |
Column | HTML <col> or CSS |
Cell | HTML <td>, <th> |
Image | HTML <img> |
Style | CSS class or inline style |
HeadersFooters | RenderingOptions.HtmlHeader/Footer |
PageSetup | RenderingOptions.* |
PdfDocumentRenderer | ChromePdfRenderer |
Styling Comparison
MigraDoc uses property-based styling on document elements:
// MigraDoc styling
paragraph.Format.Font.Size = 16;
paragraph.Format.Font.Bold = true;
paragraph.Format.Font.Color = Colors.DarkRed;
paragraph.Format.SpaceBefore = 10;// MigraDoc styling
paragraph.Format.Font.Size = 16;
paragraph.Format.Font.Bold = true;
paragraph.Format.Font.Color = Colors.DarkRed;
paragraph.Format.SpaceBefore = 10;IronPDF uses CSS, providing access to the full CSS3 specification:
/* IronPDF CSS styling */
.heading {
font-size: 16pt;
font-weight: bold;
color: darkred;
margin-top: 10pt;
}CSS offers capabilities that MigraDoc's styling system cannot match: Flexbox layouts, CSS Grid, custom fonts via @font-face, gradients, shadows, transforms, and media queries. For teams building visually sophisticated documents, IronPDF's CSS support provides significantly more design flexibility.
When Teams Consider Moving from MigraDoc to IronPDF
Several factors drive teams to evaluate IronPDF as an alternative to MigraDoc:
Existing HTML/CSS Assets: Organizations with existing web templates, email designs, or styled content that needs PDF conversion find MigraDoc requires rebuilding these designs programmatically. IronPDF allows direct conversion of existing HTML.
Web Development Skills: Teams with strong web development skills but limited experience with MigraDoc's document model can become productive with IronPDF more quickly. The learning curve leverages familiar HTML/CSS knowledge rather than requiring mastery of a new API.
Design Requirements: Projects requiring sophisticated visual design—modern typography, complex layouts, gradients, shadows—may find MigraDoc's styling options insufficient. IronPDF's full CSS3 support enables designs that match modern web aesthetics.
Dynamic Content: Applications generating content with JavaScript—interactive charts, calculated values, conditionally rendered elements—cannot use MigraDoc's static document model. IronPDF executes JavaScript via its Chromium engine before rendering.
Code Maintenance: MigraDoc's verbose API can result in large amounts of document construction code. A complex invoice might require hundreds of lines of MigraDoc code that could be replaced with an HTML template and minimal rendering code.
Charting Requirements: MigraDoc includes basic charting functionality, but teams needing modern, interactive-style charts can use JavaScript libraries like Chart.js or D3 with IronPDF.
Installation and Setup
Both libraries install via NuGet with different package structures:
MigraDoc installation:
Install-Package PdfSharp-MigraDoc-GDIInstall-Package PdfSharp-MigraDoc-GDIIronPDF installation:
Install-Package IronPdfInstall-Package IronPdfIronPDF requires a license key configuration at application startup:
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";Both libraries support .NET Framework 4.6.2+ and .NET Core 3.1+ / .NET 5+, making them compatible with modern .NET development targeting .NET 10 and C# 14.
Performance Considerations
IronPDF initializes its Chromium rendering engine on first use, which introduces a startup delay (typically 1-3 seconds). For applications with latency-sensitive startup requirements, warming up the renderer at application initialization prevents this delay from affecting user-facing operations:
// Warm up at startup
new ChromePdfRenderer().RenderHtmlAsPdf("<html></html>");// Warm up at startup
new ChromePdfRenderer().RenderHtmlAsPdf("<html></html>");Subsequent renders execute at full speed. MigraDoc's rendering doesn't have this initialization overhead but may be slower for complex CSS layouts that Chromium handles efficiently.
Making the Decision
The choice between MigraDoc and IronPDF depends on your specific requirements:
Consider MigraDoc if: You need an open-source solution with no licensing costs, your team is already familiar with MigraDoc's document model, your documents have simple styling requirements, and you're generating structured reports without existing HTML templates.
Consider IronPDF if: You have existing HTML/CSS designs to convert, your team has web development skills, you need sophisticated styling with CSS3, your documents include JavaScript-generated content like charts, or you want to reduce code complexity for document generation.
For teams building modern .NET applications in 2025 and planning toward 2026, IronPDF's alignment with web technologies offers advantages when web and PDF output need consistent design, or when using the ecosystem of web design tools and templates.
Getting Started with IronPDF
To evaluate IronPDF for your PDF generation needs:
- Install the IronPDF NuGet package:
Install-Package IronPdf - Review the HTML to PDF tutorial for basic conversion patterns
- Explore headers and footers for professional document layouts
- Check the tutorials section for comprehensive examples
The IronPDF documentation provides detailed guidance for common scenarios including URL to PDF conversion, Razor view integration, and advanced rendering options.
MigraDoc and IronPDF represent fundamentally different approaches to PDF generation in .NET applications. MigraDoc offers an open-source, programmatic document model suited for developers comfortable with its specific API and projects with straightforward styling needs. IronPDF provides HTML-based rendering that leverages web development skills and enables sophisticated CSS-based design.
For organizations evaluating MigraDoc migration, IronPDF offers a path to simpler code, richer styling capabilities, and JavaScript support—at the cost of commercial licensing. The transition involves shifting from programmatic document construction to HTML template design, a change that many teams find reduces complexity while increasing design flexibility.
Evaluate both options against your team's skills, design requirements, and budget constraints. Understanding the architectural differences outlined in this comparison will help you make an informed decision that aligns with your PDF generation needs and development practices.