CSHTML to PDF (MVC Framework)

This code example illustrates how to convert Views into PDF documents.

To achieve this, we utilize two packages: IronPdf.Extensions.Mvc.Framework and IronPdf, which work to facilitate the rendering of Views as PDFs. The IronPdf.Extensions.Mvc.Framework package extends the capabilities of IronPdf, specifically enabling the rendering of Views into PDFs.

To perform the conversion, use the RenderView method. This method requires a few key inputs: an HttpContext, the path to the ".cshtml" file, and the necessary data to populate the ".cshtml" template. By invoking the 'Persons' action, you can seamlessly render the current View into a PDF document.

Additionally, you have access to a comprehensive set of functionalities offered by the RenderingOptions class. These include the ability to add page numbers with IronPDF, insert text and HTML headers and footers using IronPDF, and customize the PDF paper size to your requirements. You have the flexibility to make further modifications or export the resulting PDF document as necessary.