diff --git a/blazor/common/integration/blazor-with-pdf-viewer.md b/blazor/common/integration/blazor-with-pdf-viewer.md
index 98ecacbf28..6fdb01e58f 100644
--- a/blazor/common/integration/blazor-with-pdf-viewer.md
+++ b/blazor/common/integration/blazor-with-pdf-viewer.md
@@ -1,38 +1,38 @@
---
layout: post
title: Syncfusion® Blazor PDF Viewer and DataGrid Integration
-description: Step-by-step guide to integrating the Syncfusion Blazor PDF Viewer and DataGrid in Blazor Web App (Server).
+description: Step-by-step guide to integrate the Syncfusion Blazor PDF Viewer and DataGrid in Blazor Web App (Server).
platform: Blazor
control: Common
documentation: ug
---
-# Integrating Syncfusion® DataGrid with PDF Viewer in Web App (Server)
+# Integrating Syncfusion® Blazor DataGrid with PDF Viewer
-This article explains how to integrate the **Syncfusion® Blazor PDF Viewer (Next‑Gen)** together with the **Syncfusion® Blazor DataGrid** in a Blazor Web App using the Server render mode.
+This article explains how to integrate the **[Syncfusion® Blazor PDF Viewer](https://www.syncfusion.com/pdf-viewer-sdk/blazor-pdf-viewer)** together with the **[Syncfusion® Blazor DataGrid](https://www.syncfusion.com/blazor-components/blazor-datagrid)** in a Blazor Web App using Server render mode.
-This guide uses [Visual Studio Code](https://code.visualstudio.com/). If you haven’t created your Blazor app yet, follow the [Blazor getting started guide](https://blazor.syncfusion.com/documentation/getting-started/blazor-web-app?tabcontent=visual-studio-code) instructions for Visual Studio Code, then return to this article.
+If you haven’t created a Blazor Web app yet, follow the [Blazor getting started guide](https://blazor.syncfusion.com/documentation/getting-started/blazor-web-app?tabcontent=visual-studio-code) to create your project.
-### Prerequisites
+## Prerequisites
-* [System requirements for Blazor components](https://blazor.syncfusion.com/documentation/system-requirements): Ensure your development environment meets the required system specifications for using Syncfusion® Blazor components.
+* [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) or later
+* .NET CLI or [Visual Studio Code](https://code.visualstudio.com/)
+* [System requirements for Blazor components](https://blazor.syncfusion.com/documentation/system-requirements)
-### Install Syncfusion® Blazor PDF Viewer, DataGrid, and Themes NuGet Packages
+## Install Syncfusion® Blazor PDF Viewer, DataGrid, and Themes NuGet packages
-From the Server project folder (where the `.csproj` is located), install the required packages:
+From the server project folder (where the `.csproj` is located), install the required packages:
* [Syncfusion.Blazor.SfPdfViewer](https://www.nuget.org/packages/Syncfusion.Blazor.SfPdfViewer)
* [Syncfusion.Blazor.Grid](https://www.nuget.org/packages/Syncfusion.Blazor.Grid)
* [Syncfusion.Blazor.Themes](https://www.nuget.org/packages/Syncfusion.Blazor.Themes/)
- * [SkiaSharp.Views.Blazor](https://www.nuget.org/packages/SkiaSharp.Views.Blazor)
{% tabs %}
-{% highlight c# tabtitle="Package Manager" %}
+{% highlight c# tabtitle=".NET CLI" %}
dotnet add package Syncfusion.Blazor.SfPdfViewer -v {{ site.releaseversion }}
dotnet add package Syncfusion.Blazor.Grid -v {{ site.releaseversion }}
dotnet add package Syncfusion.Blazor.Themes -v {{ site.releaseversion }}
-dotnet add package SkiaSharp.Views.Blazor -v 3.119.2
dotnet restore
{% endhighlight %}
@@ -41,12 +41,12 @@ dotnet restore
N> Syncfusion® Blazor components are available in [nuget.org](https://www.nuget.org/packages?q=syncfusion.blazor). Refer to the [NuGet packages](https://blazor.syncfusion.com/documentation/nuget-packages) topic for the available NuGet package list with component details. Verify the latest versions before installation.
-### Add Required Namespaces
+## Add required namespaces
-Add Syncfusion® namespaces in the server project's **~/Components/_Imports.razor** file:
+Add Syncfusion® namespaces in the server project's **~/Components/_Imports.razor** file.
{% tabs %}
-{% highlight razor tabtitle="~/_Imports.razor" %}
+{% highlight razor tabtitle="_Imports.razor" %}
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SfPdfViewer
@@ -55,12 +55,12 @@ Add Syncfusion® namespaces in the server pr
{% endhighlight %}
{% endtabs %}
-### Register Syncfusion® Blazor Service
+## Register Syncfusion® Blazor service
-Register the Syncfusion® Blazor service in your server app’s **~/Program.cs**.
+Register the Syncfusion® Blazor service in your server app’s **~/Program.cs** file.
{% tabs %}
-{% highlight c# tabtitle=".NET 8/.NET 9/.NET 10 (~/Program.cs) Server" hl_lines="2 9 11 13" %}
+{% highlight c# tabtitle="Program.cs" hl_lines="2 9 11 13" %}
...
using Syncfusion.Blazor;
@@ -69,45 +69,45 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
-
+// Configure SignalR to support large PDF file transfers
builder.Services.AddSignalR(o => { o.MaximumReceiveMessageSize = 102400000; });
-
+// Add memory cache for PDF Viewer component caching
builder.Services.AddMemoryCache();
//Add Syncfusion Blazor service to the container.
builder.Services.AddSyncfusionBlazor();
-...
...
{% endhighlight %}
{% endtabs %}
-### Add stylesheet and script resources
+## Add stylesheet and script resources
-Add the following stylesheet and script references in the server app's `~/Components/App.razor` (inside the head/body as appropriate). Ensure no other Syncfusion theme CSS (e.g., bootstrap5.css, material.css) is referenced to avoid conflicts.
+Add the following stylesheet and script references in the server app's **~/Components/App.razor** (inside the head/body as appropriate). Ensure no other Syncfusion theme CSS (e.g., bootstrap5.css, material.css) is referenced to avoid conflicts.
{% tabs %}
-{% highlight html hl_lines="3 8 11" %}
+{% highlight html tabtitle="App.razor" hl_lines="3 8 11" %}
-
-
+
+
-
-
-
+
+
{% endhighlight %}
{% endtabs %}
-### Configure Render Mode (Server)
+N> Ensure the `Syncfusion.Blazor.Core` script is loaded before the `SfPdfViewer` script, as shown above. The PDF Viewer component depends on core Blazor functionality.
-For Server render mode, if your app's interactivity location is set to `Per page/component`, add the following directive at the top of each `~Pages/*.razor` file that requires interactive Server components:
+## Configure render mode (Server)
+
+For Server render mode, if your app's interactivity location is set to `Per page/component`, add the following directive at the top of each **~Pages/*.razor** file that requires interactive Server components.
**Per‑page directive (Server)**
@@ -122,9 +122,13 @@ For Server render mode, if your app's interactivity location is set to `Per page
N> If the `interactivity location` is set to `Global` and the app is configured for Server render mode, no per‑page directive is required.
-### Add Syncfusion® Blazor PDF Viewer and DataGrid components
+## Integrate DataGrid and PDF Viewer
+
+Add the Syncfusion® PDF Viewer and DataGrid components to any `.razor` file in the server project's `Pages` folder (for example, **~/Pages/Home.razor**).
-Add the Syncfusion® PDF Viewer (Next-Gen) and DataGrid components to a `.razor` file in the server project's `Pages` folder (for example, `~/Pages/Home.razor`):
+The example below displays a **DataGrid** with sample order data, selecting a row generates and loads a detailed PDF for that order in the **PDF Viewer**.
+
+N> Ensure that PDF files are placed in the **wwwroot/PDFs** folder of your Blazor project. The PDF filename must match the `PdfFileName` property value from the selected order record. For example, if the `PdfFileName` is `Order_1001.pdf`, the file should exist at `wwwroot/PDFs/Order_1001.pdf`.
{% tabs %}
{% highlight razor %}
@@ -132,46 +136,159 @@ Add the Syncfusion® PDF Viewer (Next-Gen) a
@page "/"
@rendermode InteractiveServer
-
PDF Viewer
-
-
-
-
-
DataGrid
-
-
-
-@code{
- public List Orders { get; set; }
+@using System.IO
+@using Microsoft.AspNetCore.Hosting
+@using Syncfusion.Blazor.Grids
+@using Syncfusion.Blazor.SfPdfViewer
+@* Inject IWebHostEnvironment to access the web root path for locating PDF files *@
+@inject IWebHostEnvironment WebHostEnvironment
+
+Dynamic PDF Viewer
+
+
+
Order Management System
+
+
+
+
+
Orders - DataGrid
+
Click on any row to view detailed order information in the PDF viewer below
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Order Details - PDF Viewer
+ @if (!string.IsNullOrEmpty(ErrorMessage))
+ {
+
@ErrorMessage
+ }
+
+
+
+
+
+
+@code {
+ // Reference to the PDF Viewer component for programmatic access
+ private SfPdfViewer2? PdfViewer;
+
+ // Collection of orders to display in the grid
+ public List Orders { get; set; } = new();
+
+ // Error message for user feedback
+ private string ErrorMessage = string.Empty;
+
+ // Initialize sample order data on component load
protected override void OnInitialized()
{
- Orders = Enumerable.Range(1, 10).Select(x => new Order()
+ // Define customer names
+ string[] customers = {
+ "Alfreds Futterkiste",
+ "Ana Trujillo Emparedados",
+ "Antonio Moreno Taquería",
+ "Blondel père et fils",
+ "Bólido Comidas preparadas"
+ };
+
+ // Define cities
+ string[] cities = { "Berlin", "Madrid", "Paris", "London", "Rome" };
+
+ // Define employee names for sales representatives
+ string[] employees = { "John Smith", "Jane Doe", "Bob Wilson", "Alice Brown", "Mike Johnson" };
+
+ // Create 5 sample orders with sequential data
+ Orders = Enumerable.Range(1, 5).Select(x => new Order()
{
OrderID = 1000 + x,
- CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
- Freight = 2 * x,
- OrderDate = DateTime.Now.AddDays(-x),
+ CustomerName = customers[x - 1],
+ EmployeeName = employees[x - 1],
+ OrderDate = DateTime.Now.AddDays(-x * 2),
+ ShipCity = cities[x - 1],
+ ShippingCost = Math.Round(15.5 + (x * 8.25), 2),
+ PdfFileName = $"Order_{1000 + x}.pdf"
}).ToList();
}
- public class Order {
- public int? OrderID { get; set; }
- public string CustomerID { get; set; }
- public DateTime? OrderDate { get; set; }
- public double? Freight { get; set; }
+ // Event handler for grid row selection - loads the corresponding PDF file
+ private async Task OnRowSelected(RowSelectEventArgs args)
+ {
+ // Clear any previous error messages
+ ErrorMessage = string.Empty;
+
+ try
+ {
+ // Construct the full path to the PDF file
+ // Note: PDF files should be placed in the wwwroot/PDFs folder of your Blazor project
+ // The filename must match the PdfFileName property value from the selected order
+ string pdfFilePath = Path.Combine(WebHostEnvironment.WebRootPath, "PDFs", args.Data.PdfFileName);
+
+ // Check if the PDF file exists before attempting to load
+ if (File.Exists(pdfFilePath))
+ {
+ // Read the PDF file as a byte array
+ var pdfBytes = await File.ReadAllBytesAsync(pdfFilePath);
+
+ // Create a memory stream from the PDF bytes
+ using var pdfStream = new MemoryStream(pdfBytes);
+
+ // Load the PDF into the viewer component
+ if (PdfViewer != null)
+ {
+ await PdfViewer.LoadAsync(pdfStream);
+ }
+ }
+ else
+ {
+ // Display error if PDF file is not found
+ ErrorMessage = $"PDF file not found: {args.Data.PdfFileName}";
+ Console.WriteLine($"PDF file not found: {pdfFilePath}");
+ }
+ }
+ catch (Exception ex)
+ {
+ // Handle and display any errors during PDF loading
+ ErrorMessage = $"Error loading PDF: {ex.Message}";
+ Console.WriteLine($"Error loading PDF: {ex.Message}");
+ }
+ }
+
+ // Data model representing an order with shipping and customer details
+ public class Order
+ {
+ public int OrderID { get; set; }
+ public string CustomerName { get; set; } = "";
+ public string EmployeeName { get; set; } = "";
+ public DateTime OrderDate { get; set; }
+ public string ShipCity { get; set; } = "";
+ public double ShippingCost { get; set; }
+ // PDF filename that corresponds to this order
+ // Important: The actual PDF file with this name must exist in wwwroot/PDFs folder
+ public string PdfFileName { get; set; } = "";
}
}
{% endhighlight %}
{% endtabs %}
-N> In Syncfusion PDF Viewer, if the [DocumentPath](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SfPdfViewer.PdfViewerBase.html#Syncfusion_Blazor_SfPdfViewer_PdfViewerBase_DocumentPath) property is not set, the PDF Viewer renders without loading a PDF. Use the **Open** toolbar option to browse and open a PDF.
-
-
-### Run the Application
+## Run the application
```
@@ -181,4 +298,37 @@ dotnet run
The app launches and renders the Syncfusion® Blazor PDF Viewer and DataGrid in your default browser.
-
+
+
+## Use cases
+
+Integrating the Syncfusion® Blazor DataGrid with PDF Viewer provides powerful solutions for various business scenarios:
+
+### Invoice management system
+
+Display a list of invoices in the DataGrid with columns for invoice number, customer name, date, and amount. When a user selects an invoice row, the PDF Viewer loads and displays the corresponding invoice PDF document. This allows users to quickly browse through invoices in the grid and view detailed invoice documents without leaving the page.
+
+### Document repository and archive
+
+Create a document management system where the DataGrid shows metadata such as document title, author, category, upload date, and file size. Users can click on a document row to preview the PDF in the viewer, enabling efficient document browsing and quick access to content without downloading files.
+
+### Report viewing dashboard
+
+Build a reporting dashboard where the DataGrid lists available reports (sales reports, financial statements, analytics) with filters for date range, department, or report type. Selecting a report row dynamically loads the PDF report in the viewer, providing a seamless experience for business users to access and review multiple reports.
+
+### Contract and agreement management
+
+Implement a contract management system displaying contract records in the DataGrid with contract number, party names, start date, end date, and status. Users can select contracts to view the full PDF document in the viewer, making it easy to manage and review legal documents, track renewals, and maintain compliance.
+
+### Educational material distribution
+
+Develop an e-learning platform where the DataGrid shows course materials, assignments, or lecture notes with columns for title, subject, instructor, and upload date. Students can click on any material to view the PDF content directly in the viewer, streamlining access to educational resources.
+
+## See also
+
+* [Getting Started with Syncfusion Blazor PDF Viewer in Blazor Web App](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/getting-started/web-app)
+* [Getting Started with Syncfusion Blazor PDF Viewer in Blazor WASM](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/blazor/getting-started/web-assembly-application)
+* [Getting Started with Syncfusion Blazor DataGrid in Blazor Web App](https://blazor.syncfusion.com/documentation/datagrid/getting-started-with-web-app)
+* [Getting Started with Syncfusion Blazor DataGrid in Blazor WASM](https://blazor.syncfusion.com/documentation/datagrid/getting-started)
+* [Blazor PDF Viewer Demo](https://liveviewereditorblazorapp.azurewebsites.net/demos/pdf-viewer/blazor-server/pdf-viewer/default-functionalities)
+* [Blazor DataGrid Demo – Overview](https://blazor.syncfusion.com/demos/datagrid/overview?theme=fluent2)
\ No newline at end of file
diff --git a/blazor/common/integration/images/blazor-datagrid-with-pdf-viewer-integration.webp b/blazor/common/integration/images/blazor-datagrid-with-pdf-viewer-integration.webp
deleted file mode 100644
index 7e66e5d698..0000000000
Binary files a/blazor/common/integration/images/blazor-datagrid-with-pdf-viewer-integration.webp and /dev/null differ
diff --git a/blazor/common/integration/images/datagrid-with-pdfviewer.webp b/blazor/common/integration/images/datagrid-with-pdfviewer.webp
new file mode 100644
index 0000000000..5521d2c364
Binary files /dev/null and b/blazor/common/integration/images/datagrid-with-pdfviewer.webp differ