Back to Devexpress

Add a JavaScript-Based Document Viewer to a Blazor WebAssembly Standalone App (Visual Studio)

xtrareports-404737-web-reporting-blazor-reporting-web-document-viewer-get-started-get-started-blazor-wasm.md

latest6.7 KB
Original Source

Add a JavaScript-Based Document Viewer to a Blazor WebAssembly Standalone App (Visual Studio)

  • Feb 09, 2026
  • 5 minutes to read

This tutorial adds a Document Viewer (DxDocumentViewer) to an application created with the Blazor WebAssembly Standalone App template.

Create a New Project

This section describes how to create a new Blazor project. If you want to add a Document Viewer to an existing application, go to Step 2.

  1. Click Create a new project on Visual Studio’s start page, select the Blazor WebAssembly Standalone App template, and click Next.

  2. Specify the project name and location, and click Next.

  3. Specify additional options, and click Create.

For more information on available Blazor templates, refer to the following topic: Tooling for ASP.NET Core Blazor.

Install NuGet Packages

Install NuGet packages required for DevExpress Reporting:

  1. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

  2. Once the window opens, select All in the Package source drop-down list in the Browse tab, and install the following NuGet packages:

  3. In the Solution Explorer , right-click the project and select Edit Project File. Add the following native dependency to the application project file:

  4. Build the project.

Register DevExpress Resources

  1. In the _Imports.razor file, register the DevExpress.Blazor.Reporting namespace:

  2. In the Program.cs file, register services required for Blazor Reporting. To do this, call the AddDevExpressBlazorReportingWebAssembly method:

  3. In the App.razor file, call the RegisterScripts(Action<ResourcesConfigurator>) method to register DevExpress client resources:

Add a Document Viewer to a Page

Create a new razor file (DocumentViewer.razor) in the Pages folder. Use the code below to generate a page with a Document Viewer component.

razor
@page "/documentviewer"

<DxDocumentViewer ReportName="TestReport">
</DxDocumentViewer>

Add navigation links to the NavMenu.razor page:

csharp
<div class="nav-item px-3">
    <NavLink class="nav-link" href="documentviewer">
        <span class="oi oi-list-rich" aria-hidden="true"></span> Document Viewer
    </NavLink>
</div>

Add Code to Load Fonts

Before the application can run in a browser, register fonts to ensure that the Skia library can use them to draw report content.

This example implements a custom service that loads fonts: FontLoader.

  1. Create the Services folder in the project. Create a new class file (FontLoader.cs) with the following content:

  2. Add a LoadFonts method call to the MainLayout.razor page:

  3. Copy the required font files (opensans.ttf) to the wwwroot/fonts folder.

Add Code to Load Reports

Reporting components require a service that translates names to report instances. This tutorial implements an IReportProviderAsync service to perform this task.

  1. Add the CustomReportProvider.cs class file to the Services folder. Copy the following content into the file:

  2. The ReportsFactory class loads a report instance from a file. Add a ReportsFactory.cs class file with the following code to your project:

  3. Register the CustomReportProvider service at application startup:

Create a Report

To perform this step, you should install DevExpress Reporting v25.2 on your machine. Refer to the following topic for more information: Run the Installation Wizard - DevExpress Unified Component Installer.

  1. Select Project -> Add New Item… to invoke the Add New Item dialog. Navigate to the Reporting node and select the DevExpress v.25.2 Report item template.

  2. Select Blank in the invoked Report Wizard page and click Finish.

  3. Modify the newly created report in the Visual Studio Report Designer. Add a label and type Hello, World!:

  4. Click the report’s smart tag and select Save… :

Run the Project

Run the project and see the result. The Document Viewer displays the TestReport:

Next Steps

Restore Data ConnectionsLearn how to implement a service that restores data connections for data-aware reports loaded in the Document Viewer.Specify Report Parameters Learn how to specify report parameters using the built-in Parameters Panel or create custom UI elements and use them to submit parameter values to the report.Handle Client-Side EventsLearn how to handle client-side events raised by the JavaScript-based Document Viewer.Customize Parameter EditorsLearn how to customize built-in parameter editors in the JavaScript-based Document Viewer.Customize the Tab PanelLearn how to customize the Document Viewer Tab Panel.Customize the ToolbarLearn how to customize the Document Viewer Toolbar.TroubleshootingThis topic lists common issues that can occur in a Web Reporting application and describes solutions. For information on how to identify the cause of an issue, refer to the following help topic: Reporting Application Diagnostics.