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 in PDFs with IronPDF, adding text and HTML headers and footers with IronPDF, and customizing PDF paper size. The resulting PDF document can be further edited or exported as needed.
How to Convert CSHTML Files to PDFs in ASP.NET MVC Core
- Install the C# library for converting CSHTML files to PDFs in C#
- Instantiate the
ChromePdfRenderer
class - Use the
RenderRazorViewToPdf
method for rendering - Pass an
IRazorViewRenderer
object and the CSHTML file path to the method - Download the resulting PDF document to the desktop