CSHTML to PDF (MVC Core)

This code example demonstrates the process of converting Views into PDFs.

Two packages, IronPdf.Extensions.Mvc.Core and IronPdf, work together to enable the rendering of Views into PDFs. The IronPdf.Extensions.Mvc.Core package serves as an extension to IronPdf, enabling the rendering of Views to PDFs.

Use the RenderRazorViewToPdf method to render Views to PDFs. This method requires an IRazorViewRenderer, the path to the ".cshtml" file, and the data required to display on the ".cshtml" file. Please visit the How to Convert View to PDF in ASP.NET Core MVC how-to article to learn more.

This action also enables you to access the full range of features provided by the RenderingOptions class, such as applying page numbers, adding text and HTML headers and footers, and customizing PDF paper size. The resulting PDF document can be further edited or exported as needed.