Discover 5 tools for generating PDF reports in ASP.NET Core: iText, QuestPDF, IronPDF, DinkToPdf, Telerik, DevExpress, and Syncfusion. Compare features, code examples, and licensing.
Discover 5 tools for generating PDF reports in ASP.NET Core: iText, QuestPDF, IronPDF, DinkToPdf, Telerik, DevExpress, and Syncfusion. Compare features, code examples, and licensing.
In enterprise applications, generating PDF reports is a critical requirement for everything from invoices and receipts to analytics dashboards and compliance documents. ASP.NET Core offers several robust libraries to streamline PDF creation, but choosing the right tool can be challenging. This guide explores five powerful tools for generating PDFs in ASP.NET Core, comparing their features, ease of use, and suitability for different scenarios. Whether you need simple text-based reports or complex, styled documents, you’ll find the right solution here.
iTextSharp (now succeeded by iText 7) is a mature, open-source library for creating and manipulating PDFs. It’s highly flexible, supporting advanced features like digital signatures, encryption, and PDF/A compliance.
Create PDFs from scratch or modify existing ones.
Add tables, images, headers, footers, and watermarks.
Support for barcodes, forms, and accessibility tags (PDF/UA).
Licensed under AGPL (free for open-source projects) or commercial licenses.
dotnet add package itext7
Code Example:
using iText.Kernel.Pdf; using iText.Layout; using iText.Layout.Element; public byte[] GeneratePdf() { using var memoryStream = new MemoryStream(); var writer = new PdfWriter(memoryStream); var pdf = new PdfDocument(writer); var document = new Document(pdf); // Add content document.Add(new Paragraph("Hello, iText 7!")); document.Add(new Table(new float[] { 1, 2 }) .AddCell("Name") .AddCell("John Doe")); document.Close(); return memoryStream.ToArray(); }
Pros: High customization, supports advanced PDF features.
Cons: Steep learning curve; AGPL licensing requires care for commercial use.
QuestPDF is a modern, open-source library with a fluent API for designing PDFs. It’s ideal for developers who prefer declarative, code-first layouts.
Fluent API for building complex layouts.
Built-in support for tables, grids, and dynamic content.
Live preview tool for debugging.
MIT Licensed.
dotnet add package QuestPDF
using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; public byte[] GeneratePdf() { var document = Document.Create(container => { container.Page(page => { page.Size(PageSizes.A4); page.Margin(2, Unit.Centimetre); page.Content().Column(col => { col.Item().Text("Hello, QuestPDF!").Bold(); col.Item().Table(table => { table.ColumnsDefinition(columns => { columns.RelativeColumn(); columns.RelativeColumn(); }); table.Cell().Text("Name"); table.Cell().Text("John Doe"); }); }); }); }); return document.GeneratePdf(); }
Pros: Intuitive API, great for complex layouts, MIT license.
Cons: Limited PDF manipulation (e.g., cannot edit existing PDFs).
IronPDF is a commercial library that leverages Chromium to render HTML/CSS into PDFs. It’s perfect for converting Razor views or HTML templates to PDFs.
HTML-to-PDF conversion with CSS/JavaScript support.
Add headers, footers, and page numbers.
Merge or split PDFs.
Requires a commercial license.
dotnet add package IronPdf
using IronPdf; public byte[] GeneratePdf() { var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>Name: John Doe</p>"); return pdf.BinaryData; }
Pros: Simplifies HTML-to-PDF conversion, excellent CSS support.
Cons: Commercial licensing; Chromium dependency increases deployment size.
DinkToPdf is a wrapper around the wkhtmltopdf library, converting HTML to PDF using WebKit. It’s lightweight and open-source but requires native binaries.
HTML/CSS to PDF conversion.
Supports headers, footers, and TOC generation.
MIT Licensed.
Install the NuGet package:
dotnet add package DinkToPdf
Download wkhtmltopdf binaries for your OS from wkhtmltopdf.org.
using DinkToPdf; using DinkToPdf.Contracts; public class PdfService { private readonly IConverter _converter; public PdfService(IConverter converter) => _converter = converter; public byte[] GeneratePdf() { var html = "<h1>Hello, DinkToPdf!</h1><p>Name: John Doe</p>"; var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4 }, Objects = { new ObjectSettings { HtmlContent = html } } }; return _converter.Convert(doc); } }
Pros: Lightweight, accurate HTML rendering.
Cons: Dependency on native binaries; limited to HTML-to-PDF.
Syncfusion’s PDF Library is a commercial toolkit for creating, editing, and merging PDFs. It offers a comprehensive API for enterprise-grade needs.
Create PDFs from scratch or templates.
Add tables, charts, and barcodes.
PDF/A compliance and digital signatures.
Free community license for small businesses.
dotnet add package Syncfusion.Pdf.Net.Core
using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; public byte[] GeneratePdf() { using var document = new PdfDocument(); var page = document.Pages.Add(); var graphics = page.Graphics; // Add text graphics.DrawString("Hello, Syncfusion!", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Black, new PointF(10, 10)); // Add a table var grid = new PdfGrid(); grid.DataSource = new List<object> { new { Name = "John Doe" } }; grid.Draw(page, new PointF(10, 50)); using var stream = new MemoryStream(); document.Save(stream); return stream.ToArray(); }
Pros: Feature-rich, excellent documentation.
Cons: Commercial licensing; steep learning curve.
Telerik Reports by Progress Software is a powerful reporting solution for ASP.NET Core, offering a visual designer, rich data visualization, and seamless PDF export. It’s ideal for enterprise applications needing pixel-perfect reports.
Drag-and-drop report designer (desktop and web-based).
Support for charts, gauges, barcodes, and sub-reports.
Export to PDF, Excel, HTML, and more.
Integration with Telerik Report Server for centralized management.
Requires a commercial license.
dotnet add package Telerik.Reporting dotnet add package Telerik.ReportViewer.AspNetCore
Code Example
// Define a report public class SalesReport : Telerik.Reporting.Report { public SalesReport() { var dataSource = new ObjectDataSource(); dataSource.DataSource = SalesService.GetData(); var report = new Report(); report.DataSource = dataSource; var textBox = new TextBox(); textBox.Value = "Sales Report"; report.Items.Add(textBox); var table = new Table(); table.DataSource = dataSource; table.Columns.Add(new TableColumn("Product")); table.Columns.Add(new TableColumn("Revenue")); report.Items.Add(table); } } // Export to PDF var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(); var result = reportProcessor.RenderReport("PDF", new SalesReport(), null); File.WriteAllBytes("SalesReport.pdf", result.DocumentBytes);
Pros & Cons
Pros: Visual designer, enterprise-grade features, Telerik ecosystem integration.
Cons: Expensive licensing; steep learning curve.
DevExpress Reports is a feature-rich reporting suite with a focus on performance and customization. It’s widely used in enterprise environments for creating complex, data-driven PDF reports.
Visual Studio-integrated report designer.
Dashboard-style reports with charts, pivot grids, and sparklines.
PDF export with compression, encryption, and digital signatures.
Requires a commercial license.
dotnet add package DevExpress.AspNetCore.Reporting
Code Example
// Create a report class public class InvoiceReport : XtraReport { public InvoiceReport() { var dataSource = new List<Invoice> { /* Load data */ }; this.DataSource = dataSource; var detailBand = new DetailBand { Height = 50 }; var productNameLabel = new XRLabel { Location = new Point(0, 0) }; productNameLabel.DataBindings.Add("Text", null, "ProductName"); detailBand.Controls.Add(productNameLabel); this.Bands.Add(detailBand); } } // Export to PDF var report = new InvoiceReport(); report.ExportToPdf("InvoiceReport.pdf");
Pros & Cons
Pros: High-performance rendering, extensive customization, deep data analysis.
Cons: Licensing costs; complex setup for advanced features.
Tool | License | Strengths | Weaknesses |
---|---|---|---|
iText 7 | AGPL/Commercial | Advanced PDF editing, compliance | Complex API, licensing overhead |
QuestPDF | MIT | Modern API, code-first layouts | No visual designer |
IronPDF | Commercial | HTML-to-PDF simplicity | Chromium dependency |
DinkToPdf | MIT | Lightweight, HTML rendering | Native binary dependency |
Syncfusion | Commercial | Enterprise features, templates | Licensing cost |
Telerik Reports | Commercial | Visual designer, Telerik integration | High cost |
DevExpress | Commercial | High customization, performance | Expensive, complex |
For Visual Designers: Telerik Reports or DevExpress.
For HTML/CSS Workflows: IronPDF or DinkToPdf.
For Code-First Flexibility: QuestPDF or iText 7.
For Enterprise Ecosystems: Syncfusion, Telerik, or DevExpress.
With the addition of Telerik Reports and DevExpress, ASP.NET Core developers now have two more robust options for enterprise-level PDF reporting. These tools excel in environments requiring visual design interfaces, complex data visualization, and seamless integration with existing ecosystems.
Final Recommendations:
Startups/SMBs: Use QuestPDF (free) or DinkToPdf.
Enterprises: Invest in Telerik, DevExpress, or Syncfusion for scalability and support.
Compliance Needs: iText 7 for PDF/A or digital signatures.
Evaluate your project’s requirements, licensing constraints, and scalability needs to make the best choice.