IRONSOFTWAREHOME

Convert Razor to PDF in Blazor Server with C# PdfDocument

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Convert Razor components to PDF in Blazor Server using IronPDF's RenderRazorComponentToPdf method. Transform C# UI components into PDFs with minimal code and full customization for headers, footers, and page formatting.

Quickstart: Convert Razor Component to PDF in Minutes

Convert Razor components to PDF in Blazor Server applications using IronPDF. The RenderRazorComponentToPdf method transforms your Razor components into PDFs with a few lines of code. Follow this guide to integrate Razor to PDF conversion into your project with minimal setup and flexible customization options.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    // Install-Package IronPdf.Extensions.Blazor
    var pdf = new IronPdf.ChromePdfRenderer()
        .RenderRazorComponentToPdf<MyComponent>(new Dictionary<string,object> { {"persons",personsList} })
        .SaveAs("component-to-pdf.pdf");
    C#
  3. 3Deploy to test on your live environment

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

What NuGet Packages Do I Need for Razor to PDF Conversion?

The IronPdf.Extensions.Blazor package extends the main IronPdf package. Both packages are required to render Razor components to PDF documents in a Blazor Server App. This extension provides integration points for Blazor Server applications, enabling you to convert existing Razor components into PDFs without extensive refactoring.

Installing IronPdf.Extensions.Blazor automatically includes the core IronPdf library as a dependency. The extension package adds methods like RenderRazorComponentToPdf that understand Blazor's component model and properly render components with bound data. For optimal performance and latest features, use the most recent version of both packages. Check the changelog for updates and improvements.

PM > Install-Package IronPdf.Extensions.Blazor

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf.Extensions.Blazor

How Do I Render Razor Components to PDFs in Blazor Server?

A Blazor Server App project is required to convert Razor components to PDFs. Blazor Server applications run on the server and render UI updates over a SignalR connection, making them suitable for PDF generation where server-side processing is needed. This architecture ensures PDF rendering happens on the server, providing consistent results regardless of client browser or device.

Before starting, ensure you have the .NET SDK installed and Visual Studio 2019 or later with the ASP.NET and web development workload. Create a new Blazor Server App through Visual Studio's project templates or using the .NET CLI with dotnet new blazorserver. For detailed installation instructions and platform-specific requirements, see the Installation Overview.

What Model Class Structure Should I Use?

Add a standard C# class named PersonInfo. This class serves as the model for storing person information. Insert the following code:

namespace BlazorSample.Data
{
    public class PersonInfo
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }
}

This model represents the data structure passed to your Razor component and rendered in the PDF. IronPDF works with any C# object model, from simple POCOs to complex entity framework models. When designing models for PDF generation, consider how data will display in the final document and structure properties accordingly.

How Do I Implement the Razor Component for PDF Generation?

Use the RenderRazorComponentToPdf method to convert Razor components into PDFs. Access this method by instantiating the ChromePdfRenderer class. The method returns a PdfDocument object for exporting or further modification.

The returned PdfDocument supports additional modifications including conversion to PDF/A or PDF/UA formats. You can merge or split the document, rotate pages, and add annotations or bookmarks. Apply custom watermarks as needed.

Add a Razor component named Person.razor. Input the following code:

@page "/Person"
@using BlazorSample.Data;
@using IronPdf;
@using IronPdf.Extensions.Blazor;

<h3>Person</h3>

@code {
    // A parameter to receive a list of persons from the parent component.
    [Parameter]
    public IEnumerable<PersonInfo> persons { get; set; }

    // Dictionary to hold parameters that will be passed to the PDF renderer.
    public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();

    protected override async Task OnInitializedAsync()
    {
        // Initialize the persons list with some sample data.
        persons = new List<PersonInfo>
        {
            new PersonInfo { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
            new PersonInfo { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
            new PersonInfo { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
        };
    }

    private async void PrintToPdf()
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();

        // Apply text footer to the PDF pages.
        renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
        {
            LeftText = "{date} - {time}",
            DrawDividerLine = true,
            RightText = "Page {page} of {total-pages}",
            Font = IronSoftware.Drawing.FontTypes.Arial,
            FontSize = 11
        };

        Parameters.Add("persons", persons);

        // Render Razor component to PDF and save it.
        PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);
        File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
    }
}

<table class="table">
    <tr>
        <th>Name</th>
        <th>Title</th>
        <th>Description</th>
    </tr>
    @foreach (var person in persons)
    {
        <tr>
            <td>@person.Name</td>
            <td>@person.Title</td>
            <td>@person.Description</td>
        </tr>
    }
</table>

<button class="btn btn-primary" @onclick="PrintToPdf">Print to Pdf</button>
Text

This method provides access to all RenderingOptions features. Add text and HTML headers and footers, include page numbers, and adjust page dimensions and layout. RenderingOptions supports custom margins, viewport settings for responsive designs, and JavaScript execution delays for dynamic content.

For complex layouts or CSS frameworks like Bootstrap, explore responsive CSS rendering capabilities to ensure PDFs appear correctly across different page sizes.

How Do I Add Navigation to My Razor Component?

  • Navigate to the "Shared folder" and open NavMenu.razor. Add the section that will open our Razor component, Person. Our Person component will be the second option.
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
    <nav class="flex-column">
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="" Match="NavLinkMatch.All">
                <span class="oi oi-home" aria-hidden="true"></span> Home
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="Person">
                <span class="oi oi-list-rich" aria-hidden="true"></span> Person
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="counter">
                <span class="oi oi-plus" aria-hidden="true"></span> Counter
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="fetchdata">
                <span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
            </NavLink>
        </div>
    </nav>
</div>
Text

This navigation setup integrates with Blazor's routing system, allowing users to access PDF generation functionality from your application's main navigation menu. The NavLink component ensures proper highlighting of the active route.

What Does the PDF Generation Process Look Like?

Run the project and generate a PDF document. Click the "Print to PDF" button. IronPDF processes your Razor component, converts it to HTML, and renders it as a PDF using its Chrome-based rendering engine. This maintains the same visual fidelity as in modern web browsers.

Visual Studio debugging Blazor app with PDF generation code using `ChromePdfRenderer` and Razor components

The generated PDF saves in your project's output directory. Customize the save location, implement direct browser downloads, or store PDFs in cloud storage like Azure Blob Storage. For production applications, implement error handling and user feedback for scenarios where PDF generation might fail or exceed expected duration.

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

Where Can I Download a Complete Working Example?

Download the complete code for this guide as a zipped file. Open it in Visual Studio as a Blazor Server App project. The sample includes all dependencies, configurations, and example code to start immediately with Razor to PDF conversion in Blazor applications.

Download the Blazor Sample Project for Razor to PDF Conversion

Ready to see what else you can do? Check out our tutorial page here: Convert PDFs

For more advanced scenarios, see our Blazor tutorial covering additional integration patterns and best practices for using IronPDF in Blazor applications.

Frequently Asked Questions

What is the main method used by IronPDF to convert Razor components to PDFs in Blazor Server applications?

The main method used is IronPDF's `RenderRazorComponentToPdf`, which efficiently transforms Razor components into PDF documents.

How can I install the necessary packages for converting Razor to PDF using IronPDF?

You need to install the `IronPdf.Extensions.Blazor` NuGet package, which automatically includes the core `IronPdf` library for rendering Razor components to PDFs in a Blazor Server App.

What are the key steps to rendering a Razor component to a PDF in a Blazor Server application?

The key steps include downloading the IronPDF library, adding a model class, creating a Razor component and using the `RenderRazorComponentToPdf` method, integrating the component into your Blazor application's menu, and optionally downloading a sample project for guidance.

Can IronPDF handle complex layouts when converting Razor components to PDFs?

Yes, IronPDF supports responsive CSS rendering to ensure that PDFs maintain correct visuals across different page sizes, supporting complex layouts and CSS frameworks like Bootstrap.

What additional features can I implement with the `PdfDocument` returned by IronPDF?

You can further modify the document by converting it to PDF/A or PDF/UA formats, merging or splitting it, rotating pages, and adding annotations or bookmarks. You can also apply custom watermarks.

Is there a downloadable example of converting Razor components to PDF using IronPDF in a Blazor Server App?

Yes, you can download a complete, working example as a zipped file, which includes all necessary dependencies and configurations for immediate use in Visual Studio.

What advantage does using Blazor Server have for PDF generation?

Blazor Server runs on the server, which means that PDF rendering happens server-side, providing consistent rendering results regardless of the client's browser or device.

How can I ensure proper navigation when integrating a Razor component for PDF generation in a Blazor app?

Integrate the Razor component into the Blazor app's navigation system using `NavLink` components. This allows users to access the PDF generation functionality directly from the main navigation menu.

Can IronPDF add headers and footers to the generated PDFs from Razor components?

Yes, with IronPDF, you can add both text and HTML headers and footers, including page numbers, by utilizing the `RenderingOptions` features.

What is required before starting with Razor to PDF conversion in a Blazor Server project?

Ensure that you have the .NET SDK installed, along with Visual Studio 2019 or later with the ASP.NET and web development workload. You can start a new project using Visual Studio's templates or the .NET CLI.

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