Skip to content

Commit e7fe704

Browse files
committed
982436: Update UG Documentation for Secure Word Import and Export Header Support in Blazor
1 parent 00b0dc9 commit e7fe704

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

blazor/rich-text-editor/import-export.md

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,14 @@ public WordDocument GetDocument(string htmlText)
422422

423423
N> [View Sample in GitHub](https://github.com/SyncfusionExamples/blazor-rich-text-editor-export-to-html).
424424

425-
## Export Document/PDF with Authentication
425+
## Secure Exported PDF/Word with Authentication
426426

427-
You can add additional data while exporting a document from the Rich Text Editor. When exporting, the OnExport event is triggered, allowing you to:
427+
You can add additional data while exporting a Word document or PDF from the Rich Text Editor on the client side, which can be received on the server side. By using the `OnExport` event and its `CurrentRequest` and `CustomFormData` properties, you can pass authentication tokens and parameters to the controller action. On the server side, you can fetch the authentication token from the request headers and retrieve the custom form data from the request body, which retrieves the values sent using the POST method.
428428

429-
- Add custom headers to the request using the `CurrentRequest` property (for example, passing an authentication token).
430-
431-
- Send custom form data to the server using the `CustomFormData` property.
432-
433-
On the server side, you can fetch the authentication token from the request headers and retrieve the custom form data.
434-
435-
The following example demonstrates how to achieve this:
429+
The following example demonstrates how to pass authentication tokens and custom data during export:
436430

437431
{% tabs %}
438432
{% highlight razor %}
439-
440433
@using Syncfusion.Blazor.RichTextEditor
441434
<SfRichTextEditor>
442435
<RichTextEditorEvents OnExport="@Export" />
@@ -455,35 +448,66 @@ The following example demonstrates how to achieve this:
455448
};
456449
private void Export(ExportingEventArgs args)
457450
{
451+
// Add different authentication tokens based on export type
452+
var token = (args.ExportType == "Pdf" ? "Pdf Bearer token" : "Word Bearer token");
458453
args.CurrentRequest = new Dictionary<string, string>
459454
{
460-
{ "Authorization", "Bearer token" }
455+
{ "Authorization", token }
461456
};
462457
args.CustomFormData = new Dictionary<string, string>
463458
{
464459
{ "userId", "12345" }
465460
};
466461
}
467462
}
468-
469463
{% endhighlight %}
470464
{% endtabs %}
471465

472466
{% tabs %}
473-
{% highlight cshtml tabtitle="~/ExportService.cs" %}
474-
public class ExportParam
475-
{
476-
public string? html { get; set; }
477-
public object? formData { get; set; }
478-
}
479-
[AcceptVerbs("Post")]
480-
[EnableCors("AllowAllOrigins")]
481-
[Route("ExportToPdf")]
482-
public async Task<ActionResult> ExportToPdf([FromBody] ExportParam args)
467+
{% highlight controller %}
468+
469+
using System;
470+
using System.IO;
471+
using System.Net.Http.Headers;
472+
using Microsoft.AspNetCore.Mvc;
473+
using Microsoft.AspNetCore.Http;
474+
using System.Collections.Generic;
475+
using Microsoft.AspNetCore.Hosting;
476+
using Microsoft.AspNetCore.Http.Features;
477+
478+
namespace WordUpload.Controllers
479+
{
480+
[ApiController]
481+
public class WordController : ControllerBase
483482
{
484-
var authorization = Request.Headers["Authorization"];
485-
Console.WriteLine(args.formData);
486-
Console.WriteLine(args.html);
483+
private readonly IWebHostEnvironment hostingEnv;
484+
485+
public WordController(IWebHostEnvironment env)
486+
{
487+
this.hostingEnv = env;
488+
}
489+
public class ExportParam
490+
{
491+
public string? html { get; set; }
492+
public object? formData { get; set; }
493+
}
494+
[AcceptVerbs("Post")]
495+
[EnableCors("AllowAllOrigins")]
496+
[Route("api/RichTextEditor/ExportToPdf")]
497+
public async Task<ActionResult> ExportToPdf([FromBody] ExportParam args)
498+
{
499+
// Fetch authentication token from request headers
500+
var authorization = Request.Headers["Authorization"].ToString();
501+
// Access custom form data from the request body
502+
Console.WriteLine("Authorization: " + authorization);
503+
Console.WriteLine("Form Data: " + args.formData);
504+
Console.WriteLine("HTML Content: " + args.html);
505+
// Your export logic here
506+
// Validate token, process formData, generate PDF, etc.
507+
return Ok();
508+
}
487509
}
510+
}
511+
488512
{% endhighlight %}
489513
{% endtabs %}

0 commit comments

Comments
 (0)