Top PDF Generation Libraries for C# and .NET in 2025
The .NET ecosystem offers a rich variety of libraries for PDF generation in 2025. Whether you need to create documents from scratch, convert HTML to PDF, or generate reports with complex layouts, C# developers have multiple robust options. This article explores the most popular and powerful PDF libraries available for C# and .NET, providing download statistics, key features, installation guides, and practical code examples to help you choose the right tool for your project.
Most Popular C# PDF Generation Libraries: Download Statistics
Here's a comparison of download statistics for the PDF generation libraries available on NuGet. These numbers reflect the community's trust and adoption, providing valuable insight into which libraries developers prefer for PDF creation and HTML to PDF conversion in C# applications:
Library | Total Downloads | Per Day Average |
---|---|---|
PDFsharp | 34.9M | 7.0K |
iText7 | 30.3M | 9.7K |
Microsoft.Playwright | 25.6M | 17.7K |
PuppeteerSharp | 18.5M | 6.7K |
DinkToPdf | 16.8M | 5.7K |
QuestPDF | 9.7M | 5.9K |
Visual Representation of Download Trends
Below are charts illustrating the download trends for the C# PDF generation libraries. These visualizations help identify not only the most popular libraries but also emerging trends and momentum shifts in the .NET ecosystem.
Long-Term Popularity Trends of C# PDF Libraries – Last 10 Years
The following chart shows the download trends for C# PDF libraries over the past decade, sourced from NuGet Trends:
This long-term view reveals key shifts in library adoption patterns:
-
Microsoft.Playwright – rapid rise since 2021, accumulating ~25M downloads.
-
iText7 – consistent growth since 2018, reaching ~30M downloads by 2025.
-
PDFsharp – early adoption with apparent tracking issues in the visualization after 2019, despite its continued popularity (actual total: 34.9M downloads).
-
PuppeteerSharp and DinkToPdf following similar trajectories since 2020-2021.
-
QuestPDF showing strong momentum despite being the newest library.
Overall acceleration in PDF library adoption from 2021 onward, reflecting increased demand for document generation in modern .NET applications.
Usage Trends of C# PDF Libraries – Last 12 Months
For a closer look at current momentum, the chart below displays download trends over the past year:
The 12-month chart reveals consistent growth across all tracked C# PDF libraries. iText7 maintains the top position while Microsoft.Playwright shows the steepest growth curve. PuppeteerSharp and DinkToPdf follow similar moderate growth patterns, and QuestPDF demonstrates steady adoption despite being newer. This recent data highlights Microsoft.Playwright's accelerating momentum, suggesting increasing developer preference for browser-based PDF generation solutions in the .NET ecosystem.
Detailed Review of Top C# PDF Libraries
PDFsharp
PDFsharp is an open-source library for creating and processing PDF documents entirely with C# code. It provides a comprehensive API for programmatic PDF generation from scratch with precise control over layout and content.
➡️ Key Features:
- Full control over page layout and content positioning.
- Text, vector graphics, and image support.
- Document manipulation (merging, splitting).
- Low-level PDF structure access.
- Compatible with .NET Framework and .NET Core/.NET 5+.
➡️ Key Constraints:
- No HTML to PDF conversion capability.
- Requires manual positioning of all elements.
- Steeper learning curve for complex layouts.
➡️ Installation:
dotnet add package PDFsharp
➡️ Basic Document Creation:
- Code
- PDF Preview
using PdfSharp.Pdf;
using PdfSharp.Drawing;
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "PDFsharp Example";
document.Info.Author = "Your Name";
// Create a new page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing on the page
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create fonts for our text
XFont titleFont = new XFont("Arial", 28, XFontStyleEx.Bold);
XFont normalFont = new XFont("Arial", 22, XFontStyleEx.Regular);
// Draw text on the page
gfx.DrawString("PDF Generated with PDFsharp", titleFont, XBrushes.Blue,
new XPoint(50, 50), XStringFormats.TopLeft);
gfx.DrawString("• Why do C# developers never get lost?", normalFont, XBrushes.DarkBlue,
new XPoint(50, 100), XStringFormats.TopLeft);
gfx.DrawString("• Because they always follow the C# path!", normalFont, XBrushes.Black,
new XPoint(50, 140), XStringFormats.TopLeft);
// Save the document
const string filename = "PDFsharpExample.pdf";
document.Save(filename);
Console.WriteLine($"PDF created successfully: {filename}");
For a comprehensive guide on using PDFsharp, check our detailed tutorial: How to Generate PDF in C#/.NET with PDFsharp.
iText 7
iText 7 is a powerful PDF library for .NET that enables comprehensive document processing with an intuitive object-oriented architecture. As the modern successor to iTextSharp, it provides enhanced capabilities for creating, manipulating, and processing PDF documents programmatically. It offers robust HTML to PDF conversion capabilities through its pdfHTML add-on, allowing developers to transform web content into high-quality PDF documents.
➡️ Key Features:
- High-performance PDF generation.
- Advanced text and layout capabilities.
- HTML to PDF conversion.
- Digital signatures and encryption.
- PDF/A compliance for archiving.
- Form filling and creation.
➡️ Key Constraints:
- Commercial licensing required for commercial business applications.
- HTML to PDF requires additional pdfHTML add-on.
- More complex API compared to newer alternatives.
➡️ Installation:
dotnet add package itext7
For HTML to PDF conversion, add the pdfHTML add-on:
dotnet add package itext7.pdfhtml
➡️ HTML to PDF Conversion Example:
- Code
- PDF Preview
using iText.Html2pdf;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
class Program
{
// Main entry point of the program
static void Main()
{
ConvertHtmlToPdf();
Console.WriteLine("PDF has been generated successfully.");
}
// Method to convert HTML to PDF
static void ConvertHtmlToPdf()
{
// Define HTML content
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<title>iText 7 HTML to PDF</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; }
h1 { color: darkorange; }
p { margin: 20px 0; font-size: 26px; }
</style>
</head>
<body>
<h1>PDF Generated with iText 7</h1>
<p>Why was the C# developer always calm?</p>
<p><strong>Because they had a good `Try` and always `Catch` themselves.</strong></p>
</body>
</html>";
// Create output file stream
using (FileStream pdfDest = new FileStream("itext7-document.pdf", FileMode.Create))
{
// Initialize PDF document
PdfWriter writer = new PdfWriter(pdfDest);
PdfDocument pdf = new PdfDocument(writer);
pdf.SetDefaultPageSize(PageSize.A4);
// Convert HTML to PDF
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(htmlContent, pdf, converterProperties);
}
}
}
Explore our comprehensive guide: HTML to PDF in C#/.NET with iText 7.
Playwright for .NET
Playwright for .NET is Microsoft's browser automation library that provides a unified API to control Chromium, Firefox, and WebKit browsers. Originally developed for Node.js and later ported to the .NET ecosystem, it offers C# developers a powerful tool for browser automation and PDF generation. Playwright excels at converting dynamic web pages into high-fidelity PDFs with excellent support for modern CSS and JavaScript, making it ideal for capturing interactive content.
➡️ Key Features:
- Modern web standards compliance.
- Excellent handling of dynamic content.
- Support for responsive designs with custom viewports.
- Ability to capture screenshots and generate PDFs.
- Headless and headed browser mode options.
➡️ Key Constraints:
- Requires Chromium browser installation.
- Higher resource consumption.
➡️ Installation:
dotnet add package Microsoft.Playwright
➡️ PDF Generation Example:
- Code
- PDF Preview
using Microsoft.Playwright;
class Program
{
// Main entry point of the program
static async Task Main()
{
try
{
await GeneratePdfAsync();
Console.WriteLine("PDF has been generated successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}
// Method to generate PDF using Playwright
static async Task GeneratePdfAsync()
{
// Initialize Playwright
using var playwright = await Playwright.CreateAsync();
// Launch a Chromium browser
await using var browser = await playwright.Chromium.LaunchAsync();
// Create a new page
var page = await browser.NewPageAsync();
// HTML content to render
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Playwright PDF Example</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin: 40px; }
h1 { color: olive; }
p { margin: 20px 0; font-size: 26px; }
</style>
</head>
<body>
<h1>PDF Generated with Playwright</h1>
<p>What do you call a function that doesn't return?</p>
<p><strong>A void!</strong></p>
</body>
</html>";
// Set the page content
await page.SetContentAsync(htmlContent);
// Generate PDF
await page.PdfAsync(new PagePdfOptions
{
Path = "playwright-document.pdf",
Format = "a4"
});
}
}
For an in-depth tutorial on using Playwright for PDF generation, check our guide: How to Generate PDF from HTML Using Playwright in C# and .NET.
PuppeteerSharp
PuppeteerSharp is a .NET port of the popular Puppeteer JavaScript library, allowing C# developers to control headless Chrome browsers for tasks including HTML to PDF conversion. It's ideal for converting modern, JavaScript-heavy web pages to PDF documents with high fidelity and accurate rendering of interactive content.
➡️ Key Features:
- Headless Chrome browser automation.
- Excellent rendering of modern web standards.
- Support for dynamic content and JavaScript.
- Precise control over page settings and format.
- Screenshot and PDF generation capabilities.
➡️ Key Constraints:
- Requires Chrome installation and management.
- Heavier resource usage than native libraries.
➡️ Installation:
dotnet add package PuppeteerSharp
➡️ HTML to PDF Conversion Example:
- Code
- PDF Preview
using PuppeteerSharp;
using PuppeteerSharp.Media;
class Program
{
// Main entry point of the program
static async Task Main()
{
try
{
await ConvertHtmlToPdf();
Console.WriteLine("PDF has been generated successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}
// Method to convert HTML to PDF using PuppeteerSharp
static async Task ConvertHtmlToPdf()
{
// Download the Chromium browser if not already present
var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
// Launch the browser
using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
// Create a new page
using var page = await browser.NewPageAsync();
// HTML content to render
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>PuppeteerSharp PDF Example</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin: 40px; }
h1 { color: #D83F87; }
p { margin: 25px 0; font-size: 26px; }
</style>
</head>
<body>
<h1>PDF Generated with PuppeteerSharp</h1>
<p>Why did the C# developer go broke?</p>
<p><strong>Because he lost his inheritance!</strong></p>
</body>
</html>";
// Set the page content
await page.SetContentAsync(htmlContent);
// Generate PDF
await page.PdfAsync("puppeteersharp-document.pdf", new PdfOptions
{
Format = PaperFormat.A4,
PrintBackground = true,
MarginOptions = new MarginOptions
{
Top = "30px",
Right = "30px",
Bottom = "30px",
Left = "30px"
}
});
}
}
For a comprehensive tutorial on using PuppeteerSharp, check our detailed guide: HTML to PDF Conversion with PuppeteerSharp in C#/.NET.
DinkToPdf
DinkToPdf is a cross-platform wrapper for the popular wkhtmltopdf library, enabling HTML to PDF conversion in .NET applications. It uses the WebKit rendering engine to produce high-quality PDFs from HTML content with good CSS compatibility and layout preservation.
➡️ Key Features:
- WebKit-based rendering.
- Basic CSS compatibility.
- Header and footer customization.
- Table of contents generation.
- Easily integrates into .NET applications.
➡️ Key Constraints:
- Native library dependencies create cross-platform challenges.
- Limited JavaScript and modern CSS support.
- Less active maintenance than alternatives.