Skip to footer content

How to Convert Razor Pages to PDFs in ASP .NET Core Web App

In this tutorial, we explore how to convert CSHTML pages to PDF in an ASP.NET MVC web application using IronPDF. We begin by ensuring that IronPDF and its Blazor extension are installed. The process involves creating a simple Person class with properties like ID, name, title, and description to represent data. Next, we focus on the Razor View, displaying a list of persons in a table format. Each person’s details are rendered, and a print button triggers the conversion to a PDF document. The magic happens in the person.cshtml.cs file, where the OnGet method populates the person's list with sample data. When the print button is clicked, the OnPostAsync method uses the Chrome PDF renderer from IronPDF to transform the Razor page into a PDF document, which is then sent as a response to the browser for download. Navigation is facilitated through a nav link in the layout file. Running the project demonstrates the functionality: clicking the print button generates and downloads a beautifully rendered PDF document. The tutorial concludes by highlighting the ease of use IronPDF offers, encouraging users to start a free trial via a link provided in the description.

Person Class

Further Reading

How to Convert Razor Pages to PDFs in ASP.NET Core Web App

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.