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

In this tutorial, you'll learn how to create a PDF report in C# using the IronPDF library within a console application. Begin by installing IronPDF via the package manager in Visual Studio, then add the necessary namespace with using IronPdf.

In the Main method, declare a variable renderer as a new IronPdf.ChromePdfRenderer instance. Use the renderer.RenderHtmlFileAsPdf function, passing the HTML report file name as a parameter to convert it to PDF format. The HTML file, residing in the project's bin folder, is a Crystal Report exported to HTML. Save the generated PDF using the SaveAs function, naming it 'payment_report.pdf'. Run the project, and upon completion, find the PDF in the bin folder. This straightforward process efficiently converts HTML to PDF with minimal code. For further assistance, visit the IronPDF website or contact their support team.

using System; // Import system library for basic functionality
using IronPdf; // Import IronPdf library to handle PDF creation

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of ChromePdfRenderer to handle HTML to PDF conversion
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render the HTML file located in the bin folder as a PDF
        // Ensure the HTML file path is correctly specified
        var pdfDocument = renderer.RenderHtmlFileAsPdf("report.html");

        // Save the generated PDF document as "payment_report.pdf" in the bin folder
        pdfDocument.SaveAs("payment_report.pdf");

        Console.WriteLine("PDF has been successfully generated and saved.");
    }
}
using System; // Import system library for basic functionality
using IronPdf; // Import IronPdf library to handle PDF creation

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of ChromePdfRenderer to handle HTML to PDF conversion
        var renderer = new IronPdf.ChromePdfRenderer();

        // Render the HTML file located in the bin folder as a PDF
        // Ensure the HTML file path is correctly specified
        var pdfDocument = renderer.RenderHtmlFileAsPdf("report.html");

        // Save the generated PDF document as "payment_report.pdf" in the bin folder
        pdfDocument.SaveAs("payment_report.pdf");

        Console.WriteLine("PDF has been successfully generated and saved.");
    }
}
Imports System ' Import system library for basic functionality
Imports IronPdf ' Import IronPdf library to handle PDF creation

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create an instance of ChromePdfRenderer to handle HTML to PDF conversion
		Dim renderer = New IronPdf.ChromePdfRenderer()

		' Render the HTML file located in the bin folder as a PDF
		' Ensure the HTML file path is correctly specified
		Dim pdfDocument = renderer.RenderHtmlFileAsPdf("report.html")

		' Save the generated PDF document as "payment_report.pdf" in the bin folder
		pdfDocument.SaveAs("payment_report.pdf")

		Console.WriteLine("PDF has been successfully generated and saved.")
	End Sub
End Class
$vbLabelText   $csharpLabel

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

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Print a PDF Using C# with IronPDF
NEXT >
How to Parse PDF File in C#