IRONSOFTWAREHOME

How to Convert Views to PDFs in ASP.NET MVC with C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronPDF enables you to convert ASP.NET MVC Views to PDF documents using the ChromePdfRenderer.RenderView() method with just a few lines of code. The IronPdf.Extensions.Mvc.Framework package provides seamless integration with ASP.NET MVC projects for rendering CSHTML views as PDFs.

A View is a component in the ASP.NET framework used for generating HTML markup in web applications. It is part of the Model-View-Controller (MVC) pattern, commonly used in ASP.NET MVC and ASP.NET Core MVC applications. Views are responsible for presenting data to the user by rendering HTML content dynamically. The power of IronPDF's Chrome PDF Rendering Engine ensures that your views are rendered with pixel-perfect accuracy, maintaining all styling, layouts, and interactive elements.

ASP.NET Web Application (.NET Framework) MVC is a web application framework provided by Microsoft. It follows a structured architectural pattern known as Model-View-Controller (MVC) to organize and streamline the development of web applications.

  • Model: Manages data, business logic, and data integrity.
  • View: Presents the user interface and renders information.
  • Controller: Handles user input, processes requests, and orchestrates interactions between Model and View.

IronPDF simplifies the process of creating PDF files from Views within an ASP.NET MVC project. This makes PDF generation easy and direct in ASP.NET MVC. Whether you're generating invoices, reports, or any document from your web views, IronPDF provides the tools needed for professional PDF output. For a comprehensive setup guide, visit the Installation Overview page.

Quickstart: Convert ASP.NET MVC View to PDF Effortlessly

Learn how to quickly convert your ASP.NET MVC Views into PDF documents using IronPDF. With just a few lines of code, you can render your CSHTML views to high-quality PDFs, enhancing your application's functionality. IronPDF simplifies the process, making it accessible for developers at all levels. Get started by integrating IronPDF into your ASP.NET Core projects to effortlessly generate PDFs from your Views.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    // Install-Package IronPdf.Extensions.Mvc.Framework
    ChromePdfRenderer renderer = new ChromePdfRenderer();
    PdfDocument pdf = renderer.RenderView(this.HttpContext, "~/Views/Home/Persons.cshtml", persons);
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

What Extension Package Do I Need?

Why Does IronPDF Require an Extension Package?

The IronPdf.Extensions.Mvc.Framework package is an extension of the main IronPDF package. Both the IronPdf.Extensions.Mvc.Framework and IronPdf packages are required to render Views to PDF documents in ASP.NET MVC. This separation allows for optimized functionality specific to the MVC framework while maintaining the core PDF rendering capabilities.

How to Install the Extension Package?

PM > Install-Package IronPdf.Extensions.Mvc.Framework

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf.Extensions.Mvc.Framework

How Do I Render Views to PDFs?

What Project Type Do I Need?

To convert Views into PDF files, you need an ASP.NET Web Application (.NET Framework) MVC project. IronPDF supports various MVC versions and provides extensive Rendering Options to customize your PDF output according to your requirements.

How Do I Add a Model Class?

Where Should I Create the Model?

  • Navigate to the "Models" folder
  • Create a new C# class file named Person. This class serves as a model to represent individual data. Use the following code:
namespace ViewToPdfMVCSample.Models
{
    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }
}

How Do I Edit the Controller?

What Code Should I Add to the Controller?

Navigate to the "Controllers" folder and open the HomeController file. Add the Persons action using the following code:

In the provided code, the ChromePdfRenderer class is first created. To use the RenderView method, provide it with an HttpContext, specify the path to the "Persons.cshtml" file, and provide a List<Person> containing the necessary data. When rendering the View, you can utilize RenderingOptions to customize margins, add custom text and HTML headers and footers, and apply page numbers to the resulting PDF document.

Please note: The PDF document can be downloaded to the machine using the following code: File(pdf.BinaryData, "application/pdf", "viewToPdfMVC.pdf").
using IronPdf;
using System.Collections.Generic;
using System.Web.Mvc;
using ViewToPdfMVCSample.Models;

namespace ViewToPdfMVCSample.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        // GET: Person
        public ActionResult Persons()
        {
            // Create a list of Person objects
            var persons = new List<Person>
            {
                new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
                new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
                new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
            };

            if (HttpContext.Request.HttpMethod == "POST")
            {
                // Define the path to the View file
                var viewPath = "~/Views/Home/Persons.cshtml";

                // Instantiate the ChromePdfRenderer
                ChromePdfRenderer renderer = new ChromePdfRenderer();

                // Render the view to a PDF document
                PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);

                // Set headers to view the PDF in-browser
                Response.Headers.Add("Content-Disposition", "inline");

                // Return the generated PDF file
                return File(pdf.BinaryData, "application/pdf");
            }
            return View(persons);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}

How Can I Customize PDF Rendering Options?

For more advanced scenarios, you can customize the PDF output using various rendering options. Here's an example with custom margins, paper size, and additional settings:

// Advanced rendering with custom options
public ActionResult PersonsAdvanced()
{
    var persons = GetPersonsList();

    if (HttpContext.Request.HttpMethod == "POST")
    {
        var viewPath = "~/Views/Home/Persons.cshtml";
        
        // Configure the renderer with custom options
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        
        // Set custom rendering options
        renderer.RenderingOptions.MarginTop = 40;
        renderer.RenderingOptions.MarginBottom = 40;
        renderer.RenderingOptions.MarginLeft = 20;
        renderer.RenderingOptions.MarginRight = 20;
        
        // Set custom paper size
        renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
        renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;
        
        // Add header and footer
        renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
        renderer.RenderingOptions.TextHeader.CenterText = "{pdf-title}";
        renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
        renderer.RenderingOptions.TextHeader.FontSize = 12;
        
        renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
        renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
        renderer.RenderingOptions.TextFooter.FontSize = 10;
        renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
        
        // Enable JavaScript execution if needed
        renderer.RenderingOptions.EnableJavaScript = true;
        renderer.RenderingOptions.RenderDelay = 500; // Wait for JS to execute
        
        // Render the view to PDF
        PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
        
        // Optional: Apply compression to reduce file size
        pdf.CompressImages(60);
        
        Response.Headers.Add("Content-Disposition", "inline");
        return File(pdf.BinaryData, "application/pdf");
    }
    
    return View("Persons", persons);
}

For more information on optimizing margins, visit our guide on Set Custom Margins. If you need to work with specific paper dimensions, check out our Custom Paper Size documentation.

What Can I Do with the Generated PDF?

Once you obtain the PdfDocument object through the RenderView method, you can make various improvements and adjustments to it. You can convert the PDF to PDFA or PDFUA formats, apply digital signatures to the created PDF, or merge and split PDF documents as required. The library enables you to rotate pages, insert annotations or bookmarks, and apply distinct watermarks to your PDF files.

For file size optimization, consider using PDF Compression techniques. When dealing with JavaScript-heavy content, our JavaScript rendering guide provides detailed information on handling custom render delays. For various export options, see our comprehensive guide on Save & Export PDF Documents.

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

How Do I Add a View?

What Steps Should I Follow to Create the View?

  • Right-click on the newly added Person action and select "Add View."

    Visual Studio context menu showing 'Add View...' option when right-clicking on Persons() action method

  • Choose "MVC 5 View" for the new Scaffolded item.

    Visual Studio Add New Scaffolded Item dialog with MVC 5 View template selected

  • Select the "List" template and the Person model class.

    Add View dialog in Visual Studio showing Persons view configuration with List template and Person model class

This creates a .cshtml file named "Persons."

How to Add a Print Button to the View?

  • Navigate to the "Views" folder -> "Home" folder -> "Persons.cshtml" file.

To add a button that invokes the Persons action, use the code below:

@using (Html.BeginForm("Persons", "Home", FormMethod.Post))
{
    <input type="submit" value="Print Person" />
}
HTML

How Do I Add a Section to the Top Navigation Bar?

Where Should I Update the Navigation?

  • In the "Views" folder, navigate to the "Shared" folder -> "_Layout.cshtml" file. Place the "Person" navigation item after "Home."

Ensure that the values for the ActionLink method match exactly with our file name, which is "Persons."

<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
    <div class="container">
        @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
        <button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" title="Toggle navigation" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse d-sm-inline-flex justify-content-between">
            <ul class="navbar-nav flex-grow-1">
                <li>@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li>
                <li>@Html.ActionLink("Persons", "Persons", "Home", new { area = "" }, new { @class = "nav-link" })</li>
                <li>@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })</li>
            </ul>
        </div>
    </div>
</nav>
HTML

How to Run and Test the Project?

Run the Project

This shows you how to run the project and generate a PDF document.

Visual Studio showing ASP.NET MVC HomeController with Persons action method and PDF generation code

Output PDF

Where Can I Download the Complete Project?

What Does the Sample Project Include?

You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as an ASP.NET Web Application (.NET Framework) MVC project. The sample includes all the necessary configurations, model classes, controllers, and views to get you started quickly with PDF generation in your MVC applications.

Download the MVC sample project for PDF conversion

Frequently Asked Questions

How can I convert CSHTML views to PDF in ASP.NET MVC?

You can use IronPDF to convert CSHTML views to PDF documents in ASP.NET MVC by leveraging the ChromePdfRenderer.RenderView() method. This allows you to render views as PDFs with precise accuracy while maintaining layout and styling.

What is the IronPdf.Extensions.Mvc.Framework package used for?

The IronPdf.Extensions.Mvc.Framework package is an extension of the main IronPDF package, specifically designed for rendering ASP.NET MVC views to PDF documents. This package provides integration tailored to MVC projects while retaining the core PDF functionalities.

What types of projects are supported for rendering views to PDFs using IronPDF?

IronPDF supports ASP.NET Web Application (.NET Framework) MVC projects, allowing you to convert views into PDF files seamlessly within these projects.

How can I install the IronPdf.Extensions.Mvc.Framework package?

You can install the IronPdf.Extensions.Mvc.Framework package using the NuGet Package Manager in Visual Studio with the command: Install-Package IronPdf.Extensions.Mvc.Framework.

What are the key steps to generate a PDF from an ASP.NET MVC view?

To generate a PDF from an ASP.NET MVC view, you need to download the C# library, add a model class, create a controller action using the RenderView method, and scaffold a view using MVC 5.

How do I customize PDF rendering options in IronPDF?

IronPDF allows you to customize PDF rendering through various options such as setting custom margins, paper sizes, adding headers and footers, and enabling JavaScript execution. This can be achieved by configuring the ChromePdfRenderer.RenderingOptions.

Can I apply digital signatures to PDFs generated with IronPDF?

Yes, with IronPDF, you can apply digital signatures to your PDF documents for added security and validation.

What additional features can IronPDF offer for PDF enhancements?

IronPDF offers features like converting PDFs to PDFA or PDFUA, merging or splitting PDF documents, rotating pages, adding annotations or bookmarks, and applying watermarks.

How can I optimize PDF sizes using IronPDF?

You can optimize PDF sizes using IronPDF's compression techniques, which allow for reduced file sizes while maintaining quality.

Where can I find a sample project for PDF conversion in ASP.NET MVC?

You can download a complete sample project from the IronPDF website, which includes all necessary configurations to help you quickly start with PDF generation in ASP.NET MVC applications.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 20,809,720Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required