How to Create a PDF Report in C# for .NET using IronPDF

Generate PDF Reports in ASP.NET with C# or VB

IronPDF enables .NET developers to generate PDF reports from HTML, Crystal Reports, XML, and SQL Server data by rendering HTML content as PDF documents. This C# library simplifies report creation in ASP.NET applications with just a few lines of code, preserving all formatting and styling.

Quickstart: Generate PDF Reports with IronPDF

Get started with generating PDF reports using IronPDF in just a few lines of code. This quick guide enables developers to instantly convert HTML content into professional PDF documents, preserving all formatting effortlessly. Follow the example below to see how simple it is to transform your data into a polished PDF report.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    // Instantiate ChromePdfRenderer for HTML to PDF conversion
    new IronPdf.ChromePdfRenderer().RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

Step 1

How Do I Install IronPDF?

IronPdf on NuGet

Install-Package IronPdf

You can also download the IronPDF DLL manually. For advanced installation scenarios, check our comprehensive NuGet packages guide that covers configuration for Azure, AWS, Linux, Mac, and Windows platforms. If you're working with containerized applications, our Docker integration guide provides detailed setup instructions.


How to Tutorial

What Is the Methodology for Creating a PDF Report?

First generate the report as an HTML document, then render the HTML as a PDF using IronPDF. This tutorial shows you the steps to create a PDF report in ASP.NET C#. IronPDF's Chrome rendering engine ensures pixel-perfect conversion while supporting modern HTML5, CSS3, and JavaScript.

:path=/static-assets/pdf/content-code-examples/how-to/csharp-pdf-reports-render-html-file.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

renderer.RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf");
$vbLabelText   $csharpLabel

For more complex reporting needs, explore our comprehensive PDF creation tutorial which covers watermarks, compression, backgrounds, headers, footers, forms, and password protection.

How Do I Convert Crystal Reports to PDF with .NET?

Export Crystal Reports to HTML using:

File → Export → HTML 4.0

The resulting report can then be exported as a PDF using the above C# example code in the Methodology section. IronPDF provides excellent support for converting HTML files to PDF, maintaining all formatting and styles from your Crystal Reports output.

Here's an example:

:path=/static-assets/pdf/content-code-examples/how-to/csharp-pdf-reports-render-header-footer.cs
using IronPdf;
using IronSoftware.Drawing;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Add a header to very page easily
renderer.RenderingOptions.FirstPageNumber = 1;
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{url}";
renderer.RenderingOptions.TextHeader.Font = FontTypes.Arial;
renderer.RenderingOptions.TextHeader.FontSize = 12;

// Add a footer too
renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
renderer.RenderingOptions.TextFooter.Font = FontTypes.Arial;
renderer.RenderingOptions.TextFooter.FontSize = 10;
renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";

renderer.RenderHtmlFileAsPdf(@"c:\my\exported\report.html").SaveAs("report.pdf");
$vbLabelText   $csharpLabel

For advanced header and footer customization, including HTML-based headers, visit our headers and footers guide.

How Can I Convert Crystal Reports to PDF Programmatically?

If you wish to work programmatically to create a PDF from a Crystal Reports (RPT) file, it's also possible and gives you much more control. This approach integrates seamlessly with IronPDF's rendering options for complete customization.

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
using IronPdf;

public static void ExportRptToPdf(string rptPath, string pdfOutputPath)
{
    // Load the Crystal Report
    ReportDocument rpt = new ReportDocument();
    rpt.Load(rptPath);

    // Configure export options for HTML output
    DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions()
    {
        DiskFileName = @"c:\tmp\html\b.html" // Temporary HTML file
    };

    ExportOptions exportOpts = ExportOptions.CreateExportOptions();
    exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
    exportOpts.ExportFormatType = ExportFormatType.HTML40; // Export as HTML 4.0
    exportOpts.ExportDestinationOptions = diskOpts;

    // Export report to HTML
    rpt.Export();

    // Convert HTML to PDF using IronPDF
    var Renderer = new ChromePdfRenderer();
    // Add dynamic header with URL
    Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
    // Add footer with timestamp and page numbers
    Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
    Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";

    // Render the HTML file to PDF and save
    Renderer.RenderFileAsPdf(diskOpts.DiskFileName).SaveAs(pdfOutputPath);

    Console.WriteLine("Report Written To {0}", Path.GetFullPath(pdfOutputPath));
}
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
using IronPdf;

public static void ExportRptToPdf(string rptPath, string pdfOutputPath)
{
    // Load the Crystal Report
    ReportDocument rpt = new ReportDocument();
    rpt.Load(rptPath);

    // Configure export options for HTML output
    DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions()
    {
        DiskFileName = @"c:\tmp\html\b.html" // Temporary HTML file
    };

    ExportOptions exportOpts = ExportOptions.CreateExportOptions();
    exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
    exportOpts.ExportFormatType = ExportFormatType.HTML40; // Export as HTML 4.0
    exportOpts.ExportDestinationOptions = diskOpts;

    // Export report to HTML
    rpt.Export();

    // Convert HTML to PDF using IronPDF
    var Renderer = new ChromePdfRenderer();
    // Add dynamic header with URL
    Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
    // Add footer with timestamp and page numbers
    Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
    Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";

    // Render the HTML file to PDF and save
    Renderer.RenderFileAsPdf(diskOpts.DiskFileName).SaveAs(pdfOutputPath);

    Console.WriteLine("Report Written To {0}", Path.GetFullPath(pdfOutputPath));
}
$vbLabelText   $csharpLabel

How Do I Generate PDF Reports from XML?

Exporting report data as XML is still common despite the prevalence of easier-to-code formats such as JSON. IronPDF offers excellent support for XML to PDF conversion, providing multiple approaches to handle XML data.

To style XML reports, parse the XML and generate HTML with the data.

A more elegant solution is to use XSLT to convert XML directly to HTML using the XslCompiledTransform class as documented in the article Using the XslCompiledTransform Class.

The resultant HTML string or file may then be rendered as a PDF using IronPDF:

using System.IO;
using System.Xml;
using System.Xml.Xsl;
using IronPdf;

public static void ConvertXmlToPdf(string xml, string xslt, string pdfOutputPath)
{
    // Initialize XSLT transformation
    XslCompiledTransform transform = new XslCompiledTransform();
    using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
    {
        transform.Load(reader); // Load XSLT stylesheet
    }

    // Transform XML to HTML
    StringWriter results = new StringWriter();
    using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
    {
        transform.Transform(reader, null, results); // Apply transformation
    }

    // Convert the generated HTML to PDF
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    renderer.RenderHtmlAsPdf(results.ToString()).SaveAs(pdfOutputPath);
}
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using IronPdf;

public static void ConvertXmlToPdf(string xml, string xslt, string pdfOutputPath)
{
    // Initialize XSLT transformation
    XslCompiledTransform transform = new XslCompiledTransform();
    using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
    {
        transform.Load(reader); // Load XSLT stylesheet
    }

    // Transform XML to HTML
    StringWriter results = new StringWriter();
    using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
    {
        transform.Transform(reader, null, results); // Apply transformation
    }

    // Convert the generated HTML to PDF
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    renderer.RenderHtmlAsPdf(results.ToString()).SaveAs(pdfOutputPath);
}
$vbLabelText   $csharpLabel

Please visit the Convert XML to PDF in C# and VB.NET article to learn more about advanced XML transformation techniques and best practices.

How Do I Export SQL Server Reports to PDF?

Microsoft's SQL Server and the free SQL Server Express contain reporting tools. Exporting SSRS reports to a PDF in ASP.NET can be a useful use of IronPDF. For complex data visualization needs, IronPDF supports rendering JavaScript charts including popular libraries like C3.js, D3.js, and Highcharts.

Tutorial: How to locate and start Reporting Services tools (SSRS)

These reports may be generated as HTML which may then be customized and converted to PDF format using IronPDF. IronPDF's HTML string to PDF conversion feature provides complete control over the final output.

Render to HTML (Report Builder)

For enterprise environments requiring secure data access, IronPDF supports TLS website and system logins to handle authenticated report generation.

How Do I Secure PDF Reports?

To ensure a PDF report has not been modified or tampered with, digitally sign it. This is most easily achieved on a PDF report file after it has been rendered and saved to disk. IronPDF provides comprehensive PDF signing capabilities including support for Hardware Security Modules (HSM).

:path=/static-assets/pdf/content-code-examples/how-to/csharp-pdf-reports-sign-pdf.cs
using IronPdf.Signing;

// Sign our PDF Report using a p12 or pix digital certificate file
new PdfSignature("IronSoftware.pfx", "123456").SignPdfFile("signed.pdf");
$vbLabelText   $csharpLabel

If you do not have a digital signature, you can create a new digital signature file using the free Adobe Acrobat Reader on macOS and Windows. For additional security measures, explore our PDF permissions and passwords guide to control document access and editing rights.

How Do I Convert ASPX to PDF with ASP.NET Webforms?

The easiest way to serve HTML content in ASP.NET is to use the IronPdf.AspxToPdf class on the Form_Load event of an ASP.NET WebForms application. This powerful feature allows you to convert entire ASPX pages, including server-side controls and dynamic content, directly to PDF.

using IronPdf;

public static void RenderAspxToPdf()
{
    // Configure PDF rendering options
    var AspxToPdfOptions = new ChromePdfRenderOptions()
    {
        EnableJavaScript = false, // Disable JavaScript for simpler reports
        PrintHtmlBackgrounds = true, // Include background colors and images
        MarginTop = 20, // Set top margin in mm
        MarginBottom = 20, // Set bottom margin in mm
        PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait,
        PaperSize = IronPdf.Rendering.PdfPaperSize.A4
        // ...many more options available
    };

    // Render the HTML page to PDF and prompt download
    <code>AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "Report.pdf", AspxToPdfOptions)</code>;
}
using IronPdf;

public static void RenderAspxToPdf()
{
    // Configure PDF rendering options
    var AspxToPdfOptions = new ChromePdfRenderOptions()
    {
        EnableJavaScript = false, // Disable JavaScript for simpler reports
        PrintHtmlBackgrounds = true, // Include background colors and images
        MarginTop = 20, // Set top margin in mm
        MarginBottom = 20, // Set bottom margin in mm
        PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait,
        PaperSize = IronPdf.Rendering.PdfPaperSize.A4
        // ...many more options available
    };

    // Render the HTML page to PDF and prompt download
    <code>AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "Report.pdf", AspxToPdfOptions)</code>;
}
$vbLabelText   $csharpLabel

We hope this article has helped you in learning how to generate a PDF report in ASP.NET C# or VB.NET. You can also take a look through our full ASP.NET ASPX to PDF Tutorial to learn more about advanced scenarios including ASPX page to PDF settings and handling complex layouts.

Frequently Asked Questions

How do I generate PDF reports from HTML in C#?

IronPDF enables you to generate PDF reports from HTML with just one line of code: new IronPdf.ChromePdfRenderer().RenderHtmlFileAsPdf("report.html").SaveAs("report.pdf"). This preserves all HTML formatting and styling in the final PDF document.

What types of reports can be converted to PDF?

IronPDF supports converting multiple report types to PDF including HTML reports, Crystal Reports (exported as HTML 4.0), XML reports (styled with HTML), and SQL Server data reports. The library uses a Chrome rendering engine to ensure pixel-perfect conversion.

How do I install the PDF report generator library?

You can install IronPDF via NuGet Package Manager using the command 'Install-Package IronPdf', or download the DLL manually. The library supports various platforms including Azure, AWS, Linux, Mac, Windows, and Docker containers.

Can I convert Crystal Reports to PDF in .NET?

Yes, you can convert Crystal Reports to PDF using IronPDF by first exporting the Crystal Report to HTML 4.0 format (File → Export → HTML 4.0), then using IronPDF's RenderHtmlFileAsPdf method to convert the HTML output to a PDF document.

How do I create PDF reports from SQL Server data?

To create PDF reports from SQL Server data, first generate an HTML report with your data, then use IronPDF's ChromePdfRenderer to convert the HTML to PDF. The library preserves all formatting, making it ideal for database-driven reports.

Can I digitally sign PDF reports?

Yes, IronPDF allows you to digitally sign PDF reports to ensure they haven't been tampered with. This feature adds an extra layer of security and authenticity to your generated PDF documents.

Does the library support modern web standards?

IronPDF's Chrome rendering engine fully supports modern HTML5, CSS3, and JavaScript, ensuring your reports render accurately with all contemporary web styling and interactive elements preserved in the PDF output.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released