Skip to main content

Top PDF Generation Libraries for C# and .NET in 2025

· 18 min read
Michał Szymanowski
Michał Szymanowski
PDFBolt Co-Founder

Best C# Libraries for PDF Generation

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.

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:

LibraryTotal DownloadsPer Day Average
PDFsharp34.9M7.0K
iText730.3M9.7K
Microsoft.Playwright25.6M17.7K
PuppeteerSharp18.5M6.7K
DinkToPdf16.8M5.7K
QuestPDF9.7M5.9K

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:

10-Year Download Trends for C# PDF Libraries

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:

12-Month Download Trends for C# PDF Libraries

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 C#/.NET PDF Generation Library

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:

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}");
Learn More

For a comprehensive guide on using PDFsharp, check our detailed tutorial: How to Generate PDF in C#/.NET with PDFsharp.

iText 7

iText 7 C#/.NET PDF Generation Library

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:

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);
}
}
}
Learn More

Explore our comprehensive guide: HTML to PDF in C#/.NET with iText 7.

Playwright for .NET

Playwright C#/.NET PDF Generation Library

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:

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"
});
}
}
Learn More

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 C#/.NET PDF Generation Library

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:

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"
}
});
}
}
Learn More

For a comprehensive tutorial on using PuppeteerSharp, check our detailed guide: HTML to PDF Conversion with PuppeteerSharp in C#/.NET.

DinkToPdf

DinkToPdf C#/.NET PDF Generation Library

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.

➡️ Installation:

dotnet add package DinkToPdf
note

DinkToPdf requires the native wkhtmltopdf libraries for your target platform. These must be included in your project's directory. The libraries aren't included in the NuGet package and need to be downloaded separately from wkhtmltopdf download page.

➡️ HTML to PDF Conversion Example:

using System.Runtime.InteropServices;
using DinkToPdf;

class Program
{
// Main entry point of the program
static void Main()
{
try
{
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 DinkToPdf
static void ConvertHtmlToPdf()
{
// Define path to native library based on the operating system
// - Windows: libwkhtmltox.dll
// - Linux: libwkhtmltox.so
// - macOS: libwkhtmltox.dylib
string libraryPath;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
libraryPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"libwkhtmltox",
"libwkhtmltox.dll");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
libraryPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"libwkhtmltox",
"libwkhtmltox.so");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
libraryPath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"libwkhtmltox",
"libwkhtmltox.dylib");
}
else
{
throw new PlatformNotSupportedException("Current platform is not supported by DinkToPdf.");
}

Console.WriteLine($"Using native library: {libraryPath}");

// Initialize converter with the specified library path
var context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(libraryPath);
var converter = new SynchronizedConverter(new PdfTools());

// HTML content to convert
var htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>DinkToPdf Example</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin: 20px; }
h1 { color: #8A2BE2; font-size: 40px; }
p { margin: 25px 0; font-size: 30px; }
</style>
</head>
<body>
<h1>PDF Generated with DinkToPdf</h1>
<p>Why don't C# developers need glasses?</p>
<p><strong>Because they C#!</strong></p>
</body>
</html>";

// Set conversion settings
var doc = new HtmlToPdfDocument()
{
GlobalSettings =
{
ColorMode = ColorMode.Color,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 20, Right = 10, Bottom = 10, Left = 20 }
},
Objects =
{
new ObjectSettings
{
HtmlContent = htmlContent,
WebSettings = { DefaultEncoding = "utf-8" }
}
}
};

// Perform conversion
byte[] pdfBytes = converter.Convert(doc);

// Save to file
File.WriteAllBytes("dinktopdf-document.pdf", pdfBytes);
}
}

// Custom assembly load context for loading native libraries
public class CustomAssemblyLoadContext : System.Runtime.Loader.AssemblyLoadContext
{
public IntPtr LoadUnmanagedLibrary(string absolutePath)
{
return LoadUnmanagedDll(absolutePath);
}

protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
return NativeLibrary.Load(unmanagedDllName);
}
}
Learn More

For a detailed guide on DinkToPdf, read our tutorial: How to Convert HTML to PDF in C# and .NET Using DinkToPdf.

QuestPDF

QuestPDF C#/.NET PDF Generation Library

QuestPDF is a modern, open-source library for programmatic PDF generation in C# that offers a fluent API for document creation. It stands out for its elegant design, which makes complex document layouts easier to implement and maintain. With its declarative approach to document definition, QuestPDF simplifies the programmatic creation of professional reports, invoices, and other document types directly through code.

➡️ Key Features:

  • Fluent, code-first API.
  • Responsive layout engine.
  • Dynamic content arrangement.
  • Paging and headers/footers support.
  • Complex table layouts.
  • Rich text formatting.
  • SVG and image support.

➡️ Key Constraints:

  • No HTML to PDF conversion.
  • Community license free for companies with annual revenue under $1M USD. Commercial license required for companies exceeding this threshold.
  • Requires programmatic definition of all document elements.

➡️ Installation:

dotnet add package QuestPDF

➡️ Document Creation Example:

using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;

class Program
{
// Main entry point of the program
static void Main()
{
try
{
CreatePdf();
Console.WriteLine("PDF has been generated successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error generating PDF: {ex.Message}");
}
}

// Method to create PDF using QuestPDF
static void CreatePdf()
{
// Configure QuestPDF
QuestPDF.Settings.License = LicenseType.Community;

// Create and save the document
Document.Create(container =>
{
container.Page(page =>
{
// Configure page settings
page.Size(PageSizes.A4);
page.Margin(40);

// Add content
page.Content()
.PaddingVertical(20)
.Column(column =>
{
// Title
column.Item().AlignCenter().Text("PDF Generated with QuestPDF")
.FontSize(28)
.FontColor(Colors.Yellow.Darken3)
.Bold();

column.Spacing(30);

// Some content
column.Item().AlignCenter().Text("What's a C# developer's favorite breakfast?")
.FontSize(22);

column.Spacing(15);

column.Item().AlignCenter().Text("Threads and classes!")
.FontSize(22)
.Bold();
});
});
})
.GeneratePdf("questpdf-document.pdf");
}
}
Learn More

For an in-depth exploration of QuestPDF, read our detailed article: PDF Generation in C#/.NET Using QuestPDF.

Side-by-Side Comparison of the Best C# PDF Libraries

Now that we've explored each library individually, a side-by-side comparison will provide a clearer perspective on how these solutions stack up against each other across critical features and capabilities.

FeaturePDFsharpiText7PlaywrightPuppeteerSharpDinkToPdfQuestPDF
HTML to
PDF
NoYes –
with add-on
YesYesYesNo
CSS
Support
N/AModerateExcellentExcellentBasicN/A
JavaScript SupportN/ALimitedExcellentExcellentLimitedN/A
Rendering EngineCustomCustomChromiumChromiumWebKitCustom
PerformanceHighHighModerateModerateModerateHigh
Memory UsageLowModerateHighHighModerateLow
LicenseMITAGPL/
Commercial
Apache 2.0MITMITLGPL/
Commercial
Dynamic ContentNoLimitedYesYesLimitedYes –
code-based
Headers/
Footers
ManualYesYesYesYesYes
Tables SupportManualYesYes
(HTML)
Yes
(HTML)
Yes
(HTML)
Yes –
fluent API
Active DevelopmentModerateHighHighHighLowHigh

Which C# PDF Library Should You Choose? A Practical Selection Guide

With a comprehensive understanding of each library's technical specifications, let's focus on matching these tools to specific development scenarios you're likely to encounter in real-world projects.

Use CaseRecommended LibrariesReasoning
Static DocumentsQuestPDF, PDFsharpStrong layout control, efficient rendering, code-based approach.
Template Engine Compatible DocumentsDinkToPdf, Playwright, PuppeteerSharp, iText7Excellent integration with HTML template systems for dynamic content generation.
Dynamic Web ContentPlaywright, PuppeteerSharpBest rendering of modern CSS/JS, interactive content support.
High-Volume PDF GenerationPDFsharp, QuestPDF, iText7Better performance, lower resource consumption.
Enterprise RequirementsiText7Advanced security, digital signatures, PDF/A compliance.
Form ProcessingiText7Superior form creation, filling, and extraction capabilities.

Key Factors to Consider When Choosing a C# PDF Library:

  • Rendering requirements: Consider whether you need to handle dynamic web content, JavaScript, or modern CSS.
  • Performance needs: Evaluate throughput capabilities for your expected document generation volume.
  • Document complexity: Assess whether you need support for structured layouts or complex formatting.
  • Cross-platform compatibility: Verify support for your deployment environments.
  • Licensing restrictions: Review the license terms and potential commercial implications.
  • HTML support: Determine if you need HTML to PDF conversion capabilities.
  • Integration options: Consider compatibility with your existing technology stack.
  • Maintenance status: Check how actively the library is being developed and supported.

Alternative: Cloud-Based PDF Generation Services

For developers seeking alternatives to self-hosted solutions, cloud-based HTML to PDF API services like PDFBolt provide simplified integration without the complexities of managing dependencies.

These services typically offer:

  • Easy REST API implementation.
  • Consistent rendering across platforms.
  • Scalable infrastructure for high-volume document generation.
  • Advanced features like headers/footers and page formatting.
  • No need to manage browser dependencies.

Conclusion

The C# ecosystem offers a robust selection of PDF generation libraries to suit virtually any requirement. For projects requiring high-fidelity rendering of web content, browser-based solutions like Playwright and PuppeteerSharp provide excellent results. When working with structured business documents, libraries like QuestPDF and PDFsharp offer powerful APIs for precise control. For enterprise applications with advanced requirements, iText 7 delivers a comprehensive feature set.

By understanding the strengths and limitations of each library, you can confidently select the optimal solution for your specific needs, ensuring efficient and effective PDF generation in your C#/.NET applications.

Time to commit your PDF skills to production. Stay sharp! 🧠