Razor to PDF (Blazor Server)

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

[Parameter]
public IEnumerable<PersonInfo> persons { get; set; }
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();

protected override async Task OnInitializedAsync()
{
    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
    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
    PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);

    File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
}
NuGet Download
PM > Install-Package IronPdf
Razor to PDF (Blazor Server)

Razor to PDF (Blazor Server)

This example demonstrates how a Razor component can be converted into a PDF document.

The IronPdf.Extensions.Blazor package is an extension of the main IronPDF package. To convert a Razor component's content page to a PDF, both the IronPdf.Extensions.Blazor and the primary IronPdf packages are required.

In the code example below, a model called PersonInfo has already been created. In the OnInitializedAsync method, we insert multiple new PersonInfo objects into the persons List. We then associate the persons List with the string "persons" in the Parameters dictionary.

In the PrintToPdf method, we instantiate the ChromePdfRenderer class. To convert the Razor component to a PDF document, we use the RenderRazorComponentToPdf method. In the code example, we pass the Parameters dictionary to the method for rendering.

Learn to Convert Razor Components to PDF in Blazor Server
View on GitHub

Ready to Get Started?

Nuget Downloads 22,024,882Version:2026.11just released