Another useful feature of the Nevron Rich Text Editor for Blazor is that it can be used both on the server and the client. This makes it very easy
to implement scenarios where the server rich text editor component is automated to generate a document as a result of some business logic or SQL query. Then
you can directly stream (using the SaveToStream feature of the view) the generated document in NTB (Nevron Text Binary) or NTX (Nevron Text XML) formats, which are the native file formats used by the control.
This ensures that the component state is preserved and transferred exactly as specified on the server and that no formatting or content is lost during document conversion. All the client
code has to do is to load the serialized state from a stream. For example, this is what a simple server-side Blazor endpoint looks like:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// NOV must be initialized for your server environment before handling requests.
app.MapGet("/api/document", () =>
{
NRichTextView richTextView = new NRichTextView();
NParagraph paragraph = new NParagraph(
"Hello World from Nevron Rich Text Editor for Blazor");
paragraph.FontSize = 14;
richTextView.Content.Sections[0].Blocks.Insert(0, paragraph);
var stream = new MemoryStream();
try
{
richTextView.SaveToStream(stream);
stream.Position = 0;
return Results.Stream(
stream,
contentType: "application/octet-stream",
fileDownloadName: "document.bin");
}
catch
{
stream.Dispose();
throw;
}
});
Then on the client you can simply call the endpoint and get the serialized result:
using var response = await Http.GetAsync("/api/document", HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
using var responseStream = await response.Content.ReadAsStreamAsync();
using var documentStream = new MemoryStream();
await responseStream.CopyToAsync(documentStream);
documentStream.Position = 0;
m_BlazorRichTextEditor.Widget.View.LoadFromStream(documentStream);
Finally, it's worth noting that Nevron Rich Text Editor for Blazor is not just about MS Word-like text editing. The flexible architecture allows you to embed charts, barcodes, diagrams and other
content in the generated documents, making implementing a client / server application with reporting capabilities in Blazor a breeze.