Skip to content

Commit 6b66ca1

Browse files
authored
Merge pull request #6741 from syncfusion-content/982433-export-doc
982436: Update UG Documentation for Secure Word Import and Export Header Support in Blazor
2 parents 3d2b345 + 85116e8 commit 6b66ca1

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

blazor-toc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,7 @@
41674167
<li> <a href="/blazor/rich-text-editor/keyboard-support">Keyboard shortcuts</a></li>
41684168
<li> <a href="/blazor/rich-text-editor/accessibility">Accessibility</a></li>
41694169
<li> <a href="/blazor/rich-text-editor/webassembly-performance">WebAssembly Performance</a></li>
4170+
<li> <a href="/blazor/rich-text-editor/import-export">Import and Export</a></li>
41704171
<li> <a href="/blazor/rich-text-editor/miscellaneous">Miscellaneous</a></li>
41714172
<li> <a href="/blazor/rich-text-editor/events">Events</a></li>
41724173
<li>How To

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,93 @@ public WordDocument GetDocument(string htmlText)
421421
{% endtabs %}
422422

423423
N> [View Sample in GitHub](https://github.com/SyncfusionExamples/blazor-rich-text-editor-export-to-html).
424+
425+
## Securely Export Word or PDF Documents with Authentication
426+
427+
You can include custom data when exporting Word or PDF documents, such as authentication tokens or other parameters. Use the `OnExport` event with its `RequestHeader` and `CustomFormData` properties to send these values to the server. On the server side, the authentication token can be read from the request headers, and the custom data can be accessed from the request body, which contains the values sent via a POST request.
428+
429+
The following example demonstrates how to pass authentication tokens and custom data during export:
430+
431+
{% tabs %}
432+
{% highlight razor %}
433+
@using Syncfusion.Blazor.RichTextEditor
434+
<SfRichTextEditor>
435+
<RichTextEditorEvents OnExport="@Export" />
436+
<RichTextEditorToolbarSettings Items="@Items" />
437+
<RichTextEditorExportPdf ServiceUrl="@exportPdfServiceUrl" />
438+
<RichTextEditorExportWord ServiceUrl="@exportWordServiceUrl" />
439+
Rich Text Editor
440+
</SfRichTextEditor>
441+
@code {
442+
private string exportWordServiceUrl = "https://blazor.syncfusion.com/services/production/api/RichTextEditor/ExportToDocx";
443+
private string exportPdfServiceUrl = "https://blazor.syncfusion.com/services/production/api/RichTextEditor/ExportToPdf";
444+
private List<ToolbarItemModel> Items = new List<ToolbarItemModel>()
445+
{
446+
new ToolbarItemModel() { Command = ToolbarCommand.ExportPdf },
447+
new ToolbarItemModel() { Command = ToolbarCommand.ExportWord },
448+
};
449+
private void Export(ExportingEventArgs args)
450+
{
451+
// Assign different authentication tokens depending on the export type (Pdf or Word)
452+
var token = (args.ExportType == "Pdf" ? "Pdf Bearer token" : "Word Bearer token");
453+
args.RequestHeader = new Dictionary<string, string>
454+
{
455+
{ "Authorization", token }
456+
};
457+
args.CustomFormData = new Dictionary<string, string>
458+
{
459+
{ "userId", "12345" }
460+
};
461+
}
462+
}
463+
{% endhighlight %}
464+
{% endtabs %}
465+
466+
{% tabs %}
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 ExportService.Controllers
479+
{
480+
[ApiController]
481+
public class ExportController : ControllerBase
482+
{
483+
private readonly IWebHostEnvironment hostingEnv;
484+
485+
public ExportController(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+
}
509+
}
510+
}
511+
512+
{% endhighlight %}
513+
{% endtabs %}

0 commit comments

Comments
 (0)