This article provides the step-by-step instructions to integrate the Word processor in Blazor server app using Visual Studio 2019.
Steps to get started with Word processor component for Blazor:
Syncfusion.Blazor.DocumentEditor
.@using Syncfusion.Blazor.DocumentEditor
Pages
folder. For example, the DocumentEditorContainer component is added to the ~/Pages/Index.razor page.<SfDocumentEditorContainer EnableToolbar=true></SfDocumentEditorContainer>
ConfigureServices
method of Startup.cs file. public void ConfigureServices(IServiceCollection services) {
.......
.......
services.AddSyncfusionBlazor();
}
<head>
element of the ~/Pages/_Host.cshtml page.<head>
....
....
<link href="https://cdn.syncfusion.com/blazor/18.4.42/styles/material.css" rel="stylesheet" />
</head>
@using System.IO;
@using Syncfusion.Blazor.DocumentEditor;
<SfDocumentEditorContainer @ref="container" EnableToolbar=true>
<DocumentEditorContainerEvents Created="OnCreated"></DocumentEditorContainerEvents>
</SfDocumentEditorContainer>
@code {
SfDocumentEditorContainer container;
public void OnCreated(object args)
{
string filePath = "wwwroot/data/GettingStarted.docx";
using (FileStream fileStream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
WordDocument document = WordDocument.Load(fileStream, ImportFormatType.Docx);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
//To observe the memory go down, null out the reference of document variable.
document = null;
SfDocumentEditor editor = container.DocumentEditor;
editor.Open(json);
//To observe the memory go down, null out the reference of json variable.
json = null;
}
}
}
Note: As per the discussion thread #30064, please null out the reference of streams and other instances when they are no longer required. Using this approach you’ll observe the memory go down and become stable.