Syncfusion AI Assistant

How can I help you?

Getting Started with Blazor DOCX Editor in Blazor WASM

29 Apr 20265 minutes to read

Syncfusion® DOCX Editor (Document Editor) enables you to create, edit, view, and print Word documents in web applications. This section guides you through the steps to get started and create a DOCX Editor in a Blazor WebAssembly (WASM) application.

Steps to create a Blazor WASM DOCX Editor

This section explains how to include the Blazor Document Editor component in a Blazor WebAssembly (WASM) application using Visual Studio and Visual Studio Code.

Prerequisites

Create a Blazor WASM App in Visual Studio

You can create a Blazor WebAssembly App using Visual Studio via Microsoft Templates.

Install Syncfusion® Blazor Nuget packages

To add Blazor Document Editor component in the application, follow the steps below.

Alternatively, you can utilize the following package manager command to achieve the same.

Install-Package Syncfusion.Blazor.WordProcessor -Version 33.2.3
Install-Package Syncfusion.Blazor.Themes -Version 33.2.3

NOTE

Syncfusion® Blazor DOCX Editor are available on nuget.org. Refer to the NuGet packages topic for the complete list of packages and component details.

Prerequisites

Create a new Blazor WASM App in Visual Studio Code

You can create a Blazor WebAssembly App using Visual Studio Code via Microsoft Templates.

Alternatively, create a WebAssembly application using the following terminal commands (Ctrl+`).

dotnet new blazorwasm -o BlazorApp
cd BlazorApp

Install Syncfusion® Blazor Nuget packages

dotnet add package Syncfusion.Blazor.WordProcessor -v 33.2.3
dotnet add package Syncfusion.Blazor.Themes -v 33.2.3
dotnet restore

NOTE

Syncfusion® Blazor DOCX Editor are available on nuget.org. Refer to the NuGet packages topic for available NuGet packages list with component details.

Register Syncfusion® Blazor Services

Open ~/_Imports.razor file and import the Syncfusion.Blazor and Syncfusion.Blazor.DocumentEditor namespaces.

@using Syncfusion.Blazor
@using Syncfusion.Blazor.DocumentEditor

Now register the Syncfusion® Blazor Service in the ~/Program.cs file of your Blazor WebAssembly App.

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Syncfusion.Blazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddSyncfusionBlazor();
await builder.Build().RunAsync();
....

Add Themes and Script References

Add the following stylesheet and script to the head section of ~/index.html file. The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Reference the stylesheet and script in the <head> of the main page as follows:

<head>
    ....
    <link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
    <script src="_content/Syncfusion.Blazor.WordProcessor/scripts/syncfusion-blazor-documenteditor.min.js" type="text/javascript"></script>
</head>

NOTE

Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.

Add the Syncfusion® Document Editor component

Add the Syncfusion® Blazor Document Editor component in the ~/Pages/Index.razor file.

<SfDocumentEditorContainer EnableToolbar=true></SfDocumentEditorContainer>

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. This will render the Syncfusion® Blazor Document Editor component in your default web browser.

You can download a complete working sample from GitHub.

Blazor DocumentEditor