Introduction
Blazor is a .NET Core web framework that runs C# code on the browser using WebAssembly. It offers an alternative to JavaScript frameworks like React, Angular, and Vue. A Blazor App offers several benefits over these alternatives, such as faster execution times and better performance. Blazor relies on Razor view syntax, which is a markup language similar to HTML. Blazor uses C# code to run in web browsers, and Blazor App code can be authored with Visual Studio. We can also create a standalone Blazer web assembly app without any server-side app.
You can also host Razor components in native mobile and desktop apps that render to a Web View control. Regardless of the hosting model, if you use Razor Components they'll work the same way. You can use the same Razor components in any of these models unchanged.
Blazor server hosting model
ASP.NET Core apps can be configured to use Blazor Server as the hosting model, which means that the app is executed on the server side instead of in a browser. Updating UI content and handling events happen over a SignalR connection using the WebSockets protocol. Blazor allows the scaling apps to handle multiple client connections.
The state on the server associated with each connected client is called a circuit. Circuits don't get tied to a specific network connection and can tolerate - temporarily - interrupted connections. In addition, clients can reconnect to the server when they want to even after going offline.
With a server-side Blazor app, each browser screen requires its circuit and components will be rehydrated by the server. If graceful termination occurs, the circuit along with any associated hardware or drivers is immediately released.
The Blazor script (blazor.server.js) establishes the SignalR connection with the server on the client's side. The script is served to the client-side app from an embedded resource in ASP.NET Core's shared framework. The client-side app is responsible for persisting and restoring its state as needed. From the docs: A hosted client app can interact with its backend server app over the network using a variety of messaging frameworks and protocols, such as web API, gRPC-web, and SignalR.

Iron pdf.NET pdf library
IronPDF.NET is a .NET library for generating PDF documents and manipulating existing ones. It has a set of APIs to generate PDF documents in different ways - from rendering an existing HTML page to converting an image format to PDF. I have found to read, create & export PDFs from within Blazor Server Hosting Model Apps.
IronPDF supports the latest .NET Core version. It also supports the Blazor project type. In this article, we'll see how we can create PDFs in Blazor server apps using IronPDF. Explore more examples of Blazor server tutorials here.
Generate pdf in Blazor server apps
Let's see how Blazor server Apps work. I'll use the IronPDF library for generating PDFs in the Blazor server hosting model application. Let's see how to do it.
Step 1. Creating Blazor server app
Open Visual Studio and search for Blazor Server App in Application templates. Select it and hit the next button.

Now give the proper name to the project and click the "next" button.

Select the latest .NET Core framework. You can choose any version according to your requirements but the latest version is recommended. After selecting the .NET framework, hit the Create button. It'll create a Blazor Server Application.

Step 2. Install iron pdf
Now, it's time to install Iron PDF. Go to the tools from the top menu. From the dropdown, hover on "NuGet Package Manager" and from the sub-menu, select "Package Manager Console". It'll open the console for installing NuGet packages into your .NET Core project.

Run the following command in the Package Manager Console.
install-package IronPDF
Alternatively, use the Nuget Package Manager GUI and search for IronPDF.
This will start installing IronPDF in our project.

Step 3. Create Razor component
Now create a new Razor component in the "Pages" folder.
Right-click on the "Pages" folder and from the submenu of the "Add" option, select "New Item". It'll open a new dialog box.

Select Razor Component put "GeneratePDF" as the name and hit the "Add" button. The razor component will be added to the "Pages" folder.

Now open "GeneratePDF.razor" and write the following server-side code.
At first, I define the page route and provide the name "/pdf". After that, I inject IJSRuntime JS to save the generated PDF file. I create the Page Title and heading using HTML tags. After that, I create Textarea and bind it with the variable "htmlString". I'll use the "htmlString" variable to get the text written in the text area for generating PDF. I'll define the htmlString variable in the code part later. I create a button and bind it with the CreatePDF function using the onclick function. Let's move to the code part.
In the code, I create the variable name "htmlString". After that, I create an async function CreatePDF. In the function, I initiate "ChromePdfRenderer" and use the "RenderHtmlAsPdf" function to convert HTML to PDF. After that, I convert the generated PDF into a stream object to make it a downloadable file and invoke the JS function.
@page "/pdf"
@inject IJSRuntime JS
<PageTitle>Create PDF</PageTitle>
<h1>Create PDF</h1>
<div class="form-outline">
<textarea class="form-control w-50" id="htmltopdf" rows="8" cols="16" @bind="htmlString"></textarea>
<button class="btn btn-primary mt-4" @onclick="CreatePDF">Create PDF</button>
</div>
@code {
private string htmlString { get; set; } = default!;
private async Task CreatePDF()
{
var render = new IronPdf.ChromePdfRenderer();
var doc = render.RenderHtmlAsPdf(htmlString);
using var Content = new DotNetStreamReference(stream: doc.Stream);
await JS.InvokeVoidAsync("SubmitHTML", "ironpdf.pdf", Content);
}
}






Riaan GPosted Oct 14, 2018, 12:47 PM
Has anyone used [Authorize] with Server-side Blazor? I guess the "@page" is now the PageModel. Using your example, it would be great to protect the /fetchdata resource seeing that Server-side has full access to .net core.
Ano MepaniPosted Aug 18, 2018, 7:41 AM
Https://youtu.be/7Eh_l7jEcCo nice to see this article used in reference purpose in asp.net community standup meeting 5:00 minute
Nen NePosted Jul 31, 2018, 4:09 AM
I could just use webapi instead of Blazor server, which gives me everything. am i missing something here ??
Georgi VatsovPosted Jul 31, 2018, 3:45 AM
Very useful article. Thank you. Just a minor addition: another difference in the Blazor server-side app in comparison to the client-side is that in the startup file we have "app.UseServerSideBlazor<App.Startup>();" instead of "app.UseBlazor<Client.Program>();"