IRONSOFTWAREHOME
CSHTML to PDF (Razor Pages)

// PM > Install-Package IronPdf.Extensions.Razor

using IronPdf.Razor.Pages;

public IActionResult OnPostAsync()
{
    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" }
    };

    ViewData["personList"] = persons;

    ChromePdfRenderer renderer = new ChromePdfRenderer();

    // Render Razor Page to PDF document
    PdfDocument pdf = renderer.RenderRazorToPdf(this);

    Response.Headers.Add("Content-Disposition", "inline");

    return File(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf");
}
' PM > Install-Package IronPdf.Extensions.Razor

Imports IronPdf.Razor.Pages

Public Function OnPostAsync() As IActionResult
    persons = New List(Of Person) From {
        New Person With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
        New Person With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
        New Person With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
    }

    ViewData("personList") = persons

    Dim renderer As New ChromePdfRenderer()

    ' Render Razor Page to PDF document
    Dim pdf As PdfDocument = renderer.RenderRazorToPdf(Me)

    Response.Headers.Add("Content-Disposition", "inline")

    Return File(pdf.BinaryData, "application/pdf", "razorPageToPdf.pdf")
End Function
NuGet Download
PM > Install-Package IronPdf
CSHTML to PDF (Razor Pages)

CSHTML to PDF (Razor Pages)

This code example demonstrates the process of converting a Razor page into PDFs.

To achieve this in an ASP.NET Core Web App, you'll require two packages: IronPdf.Extensions.Razor and IronPdf. These packages work together to enable the rendering of Razor pages into PDFs.

By rendering from Razor pages, you gain access to the full range of features provided by the RenderingOptions class. The resulting PDF document can be further edited or exported as needed.

In this example, the Razor page's content is rendered into a PDF using IronPDF's ChromePdfRenderer. You can specify rendering options, such as paper size and title, through RenderingOptions. The generated PDF can be saved as a file or directly served as content for browser display. The response headers can be adjusted to allow for inline display or file download.

Learn to Convert Razor Pages to PDFs with IronPDF
View on GitHub

Ready to Get Started?

Nuget Downloads 20,878,335Version:2026.9just released

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