Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
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
Further Reading: Generate PDF Reports in ASP.NET with C# or VB