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 above, 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.

How to Convert Razor Components to PDFs in Blazor Server

  1. Install the C# library for converting Razor components to PDFs in C#
  2. Prepare a model to store the information
  3. Instantiate the ChromePdfRenderer class
  4. Pass the Dictionary object containing the data to the RenderRazorComponentToPdf method
  5. Download the resulting PDF document to the desktop