Skip to footer content

How to Convert CSHTML to PDF Using Razor Headlessly in C#

Unlock the power of seamless PDF generation in your ASP.NET MVC Core projects by watching this step-by-step video tutorial and transform your Razor views into professional-grade PDFs with ease using IronPDF!

In this video tutorial, viewers learn how to convert Razor views to PDF files in an ASP.NET MVC Core project using IronPDF. The tutorial begins by ensuring that necessary NuGet packages, such as IronPDF and Razor.Templating.Doc, are installed. The process starts with adding a new Razor view within the project's views folder, creating a data.cshtml file, and populating it with HTML content, such as tables displaying names and descriptions.

The next step involves editing the Program.cs file to set up an endpoint that handles the PDF generation process. This involves configuring IronPDF with a license key for full functionality and enabling logging for debugging purposes. The Razor Template Engine's RenderAsync method is used to convert the Razor view to an HTML string, followed by instantiating a Chrome PDF Renderer to handle the conversion from HTML to PDF.

Finally, the tutorial demonstrates accessing the /printPDF endpoint to download the generated PDF, effectively rendering the Razor view's content. The video concludes by encouraging viewers to engage with the content through likes and subscriptions, and suggesting a trial of the software with a link provided in the description.

Related Videos