Skip to content

Commit c1afac9

Browse files
Integrated latest changes at 12-11-2025 1:30:05 PM
1 parent 9f099ad commit c1afac9

File tree

2 files changed

+147
-8
lines changed

2 files changed

+147
-8
lines changed

ej2-javascript/rich-text-editor/import-and-export.md

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: Content Import/Export in ##Platform_Name## Rich Text Editor control | Syncfusion
3+
title: Import/Export in ##Platform_Name## Rich Text Editor | Syncfusion
44
description: Learn here all about Content Import/Export in Syncfusion ##Platform_Name## Rich Text Editor control of Syncfusion Essential JS 2 and more.
55
platform: ej2-javascript
66
control: IContent Import/Export
@@ -15,7 +15,7 @@ domainurl: ##DomainURL##
1515

1616
The Rich Text Editor provides functionality to import content directly from Microsoft Word documents, preserving the original formatting and structure. This feature ensures a smooth transition of content from Word to the editor, maintaining elements such as headings, lists, tables, and text styles.
1717

18-
To integrate an `ImportWord` option into the Rich Text Editor toolbar, you can add it as a custom toolbar [items](../api/rich-text-editor/toolbarSettings/#items) using the items property in toolbarSettings.
18+
To integrate an `ImportWord` option into the Rich Text Editor toolbar, you can add it as a custom toolbar [items](https://ej2.syncfusion.com/documentation/api/rich-text-editor/toolbarSettings#items) using the items property in toolbarSettings.
1919

2020
The following example illustrates how to set up the `ImportWord` in the Rich Text Editor to facilitate content importation from Word documents:
2121

@@ -46,7 +46,46 @@ The following example illustrates how to set up the `ImportWord` in the Rich Tex
4646
{% previewsample "page.domainurl/code-snippet/rich-text-editor/import-cs1" %}
4747
{% endif %}
4848

49-
Here’s how to handle the server-side action for importing content from Word.
49+
## Secure importing with authentication
50+
51+
The Rich Text Editor provides functionality to import Word documents with authentication for secure importing.
52+
53+
The [wordImporting](https://ej2.syncfusion.com/documentation/api/rich-text-editor/index-default#wordimporting) event provides [UploadingEventArgs](https://ej2.syncfusion.com/documentation/api/uploader/uploadingeventargs) for secure Word file import. Use `currentRequest` to add authentication headers and `customFormData` to include extra parameters in the POST body along with the uploaded file. On the server, read headers and form data from the request to validate and process the import securely.
54+
55+
The following example demonstrates how to configure `wordImporting` for secure importing:
56+
57+
```ts
58+
59+
import { RichTextEditor, Toolbar, Link, Image, Count, HtmlEditor, QuickToolbar, ImportExport } from '@syncfusion/ej2-richtexteditor';
60+
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
61+
RichTextEditor.Inject(Toolbar, Link, Image, Count, HtmlEditor, QuickToolbar, ImportExport);
62+
63+
const hostUrl: string = 'https://services.syncfusion.com/js/production/';
64+
const importEditor: RichTextEditor = new RichTextEditor({
65+
toolbarSettings: {
66+
items: ['ImportWord']
67+
},
68+
insertImageSettings: {
69+
saveUrl: hostUrl + 'api/RichTextEditor/SaveFile',
70+
removeUrl: hostUrl + 'api/RichTextEditor/DeleteFile',
71+
path: hostUrl + 'RichTextEditor/'
72+
},
73+
importWord: {
74+
serviceUrl: hostUrl + 'api/RichTextEditor/ImportFromWord',
75+
},
76+
enableXhtml: true,
77+
wordImporting: onWordImport
78+
});
79+
importEditor.appendTo('#importEditor');
80+
function onWordImport(args: UploadingEventArgs): void {
81+
let accessToken = "Authorization_token";
82+
// adding authorization header
83+
args.currentRequest.setRequestHeader('Authorization', accessToken)
84+
// adding custom form Data
85+
args.customFormData = [{'userId': '1234'}];
86+
}
87+
```
88+
Here’s how to handle the server-side action for importing content from Word with authentication.
5089

5190
```csharp
5291

@@ -60,6 +99,10 @@ public class RichTextEditorController : Controller
6099
[Route("ImportFromWord")]
61100
public IActionResult ImportFromWord(IList<IFormFile> UploadFiles)
62101
{
102+
// Read headers (e.g., Authorization)
103+
var authorization = Request.Headers["Authorization"].ToString();
104+
// Read custom form data (from args.customFormData)
105+
var formData = Request.Form("userId").ToString();
63106
string HtmlString = string.Empty;
64107
if (UploadFiles != null)
65108
{
@@ -116,7 +159,7 @@ public class RichTextEditorController : Controller
116159

117160
The Rich Text Editor's export functionality allows users to convert their edited content into PDF or Word documents with a single click, preserving all text styles, images, tables, and other formatting elements.
118161

119-
You can add `ExportWord` and `ExportPdf` tools to the Rich Text Editor toolbar using the toolbarSettings [items](../api/rich-text-editor/toolbarSettings/#items) property.
162+
You can add `ExportWord` and `ExportPdf` tools to the Rich Text Editor toolbar using the toolbarSettings [items](https://ej2.syncfusion.com/documentation/api/rich-text-editor/toolbarSettings#items) property.
120163

121164
The following example demonstrates how to configure the `ExportWord` and `ExportPdf` tools in the Rich Text Editor, facilitating the export of content into Word or PDF documents:
122165

@@ -147,7 +190,65 @@ The following example demonstrates how to configure the `ExportWord` and `Export
147190
{% previewsample "page.domainurl/code-snippet/rich-text-editor/export-cs1" %}
148191
{% endif %}
149192

150-
Here’s how to handle the server-side action for exporting content to PDF and Microsoft Word
193+
## Secure exporting with authentication
194+
195+
The Rich Text Editor provides functionality to export Word or PDF documents with authentication for secure exporting.
196+
197+
The [documentExporting](https://ej2.syncfusion.com/documentation/api/rich-text-editor/index-default#documentexporting) event provides `ExportingEventArgs` for secure export of Word or PDF files. Use `exportType` to identify the format, `currentRequest` to add authentication headers, and `customFormData` to send extra parameters in the POST body. On the server, read headers and custom data to validate and process the export securely.
198+
199+
The following example demonstrates how to configure `documentExporting` for secure exporting:
200+
201+
```ts
202+
import { RichTextEditor, Toolbar, Link, Image, HtmlEditor, QuickToolbar, Table, PasteCleanup, ImportExport } from '@syncfusion/ej2-richtexteditor';
203+
RichTextEditor.Inject(Toolbar, Link, Image, HtmlEditor, QuickToolbar, Table, PasteCleanup, ImportExport);
204+
205+
const hostUrl: string = 'https://services.syncfusion.com/js/production/';
206+
const exportEditor: RichTextEditor = new RichTextEditor({
207+
toolbarSettings: {
208+
items: ['ExportWord', 'ExportPdf']
209+
},
210+
insertImageSettings: {
211+
saveUrl: hostUrl + 'api/RichTextEditor/SaveFile',
212+
removeUrl: hostUrl + 'api/RichTextEditor/DeleteFile',
213+
path: hostUrl + 'RichTextEditor/'
214+
},
215+
exportWord: {
216+
serviceUrl: hostUrl + 'api/RichTextEditor/ExportToDocx',
217+
fileName: 'RichTextEditor.docx',
218+
stylesheet: `
219+
.e-rte-content {
220+
font-size: 1em;
221+
font-weight: 400;
222+
margin: 0;
223+
}
224+
`
225+
},
226+
exportPdf: {
227+
serviceUrl: hostUrl + 'api/RichTextEditor/ExportToPdf',
228+
fileName: 'RichTextEditor.pdf',
229+
stylesheet: `
230+
.e-rte-content{
231+
font-size: 1em;
232+
font-weight: 400;
233+
margin: 0;
234+
}
235+
`
236+
},
237+
enableXhtml: true,
238+
documentExporting : onDocumentExporting
239+
});
240+
exportEditor.appendTo('#exportEditor');
241+
function onDocumentExporting(args: ExportingEventArgs): void {
242+
const accessToken = "Authorization_token";
243+
// Specify export type (e.g., 'Pdf' or 'Word')
244+
args.exportType = 'Pdf';
245+
// Add authentication header
246+
args.currentRequest = [{ Authorization: accessToken }];
247+
// Add custom form data
248+
args.customFormData = [{ userId: '1234' }, { exportMode: 'secure' }];
249+
}
250+
```
251+
Here’s how to handle the server-side action for exporting content to PDF and Microsoft Word with authentication
151252

152253
```csharp
153254

@@ -161,6 +262,10 @@ public class RichTextEditorController : Controller
161262
[Route("ExportToPdf")]
162263
public ActionResult ExportToPdf([FromBody] ExportParam args)
163264
{
265+
// Read headers (e.g., Authorization)
266+
var authorization = Request.Headers["Authorization"].ToString();
267+
// Read custom form data (from args.customFormData)
268+
var formData = args.CustomFormData;
164269
string htmlString = args.html;
165270
if (htmlString == null && htmlString == "")
166271
{
@@ -235,6 +340,8 @@ public class RichTextEditorController : Controller
235340
public class ExportParam
236341
{
237342
public string html { get; set; }
343+
// For receiving custom form data
344+
public List<Dictionary<string,string>> CustomFormData { get; set; }
238345
}
239346
}
240347

ej2-javascript/rich-text-editor/smart-editing/mail-merge.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ To enable mail merge functionality, the Rich Text Editor toolbar is extended wit
2727
{% tabs %}
2828
{% highlight ts tabtitle="app.ts" %}
2929

30+
{% raw %}
31+
3032
const mailMergeEditor: RichTextEditor = new RichTextEditor({
3133
toolbarSettings: {
3234
items: [
@@ -40,6 +42,8 @@ const mailMergeEditor: RichTextEditor = new RichTextEditor({
4042
});
4143
mailMergeEditor.appendTo('#mailMergeEditor');
4244

45+
{% endraw %}
46+
4347
{% endhighlight %}
4448
{% endtabs %}
4549

@@ -48,6 +52,8 @@ mailMergeEditor.appendTo('#mailMergeEditor');
4852
{% tabs %}
4953
{% highlight js tabtitle="index.js" %}
5054

55+
{% raw %}
56+
5157
var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
5258
toolbarSettings: {
5359
items: [
@@ -61,6 +67,8 @@ var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
6167
});
6268
mailMergeEditor.appendTo('#mailMergeEditor');
6369

70+
{% endraw %}
71+
6472
{% endhighlight %}
6573
{% endtabs %}
6674
{% endif %}
@@ -74,6 +82,8 @@ The **DropDownButton** component displays a list of merge fields such as First N
7482
{% tabs %}
7583
{% highlight ts tabtitle="app.ts" %}
7684

85+
{% raw %}
86+
7787
let insertField: DropDownButton = new DropDownButton({
7888
items: [
7989
{ text: 'First Name' },
@@ -100,6 +110,8 @@ function onItemSelect(args: MenuEventArgs): void {
100110
);
101111
}
102112

113+
{% endraw %}
114+
103115
{% endhighlight %}
104116
{% endtabs %}
105117

@@ -108,6 +120,8 @@ function onItemSelect(args: MenuEventArgs): void {
108120
{% tabs %}
109121
{% highlight js tabtitle="index.js" %}
110122

123+
{% raw %}
124+
111125
var insertField = new ej.splitbuttons.DropDownButton({
112126
items: [
113127
{ text: 'First Name' },
@@ -139,6 +153,8 @@ function onItemSelect(args) {
139153
}
140154
}
141155

156+
{% endraw %}
157+
142158
{% endhighlight %}
143159
{% endtabs %}
144160
{% endif %}
@@ -152,10 +168,12 @@ The **Mention** control provides an alternative way to insert placeholders by ty
152168
{% tabs %}
153169
{% highlight ts tabtitle="app.ts" %}
154170

171+
{% raw %}
172+
155173
const mentionObj: Mention = new Mention({
156174
dataSource: mergeData,
157175
target: '#mailMergeEditor',
158-
mentionChar: <code>&#123;&#123;</code>,
176+
mentionChar: `{{`,
159177
fields: { text: 'text' },
160178
allowSpaces: true,
161179
popupWidth: '250px',
@@ -164,6 +182,8 @@ const mentionObj: Mention = new Mention({
164182
});
165183
mentionObj.appendTo('#mentionField');
166184

185+
{% endraw %}
186+
167187
{% endhighlight %}
168188
{% endtabs %}
169189

@@ -172,18 +192,22 @@ mentionObj.appendTo('#mentionField');
172192
{% tabs %}
173193
{% highlight js tabtitle="index.js" %}
174194

195+
{% raw %}
196+
175197
var mergeObj = new ej.dropdowns.Mention({
176198
dataSource: mergeData,
177199
fields: { text: 'Name', value: 'Field' },
178200
displayTemplate: '<span>{{${Field}}}</span>',
179201
popupWidth: '250px',
180202
popupHeight: '200px',
181203
target: mailMergeEditor.inputElement,
182-
mentionChar: <code>&#123;&#123;</code> ,
204+
mentionChar: `{{` ,
183205
allowSpaces: true,
184206
});
185207
mergeObj.appendTo('#mentionField');
186208

209+
{% endraw %}
210+
187211
{% endhighlight %}
188212
{% endtabs %}
189213
{% endif %}
@@ -195,7 +219,9 @@ When the **Merge Data** button is clicked, the editor content is processed to re
195219
{% if page.publishingplatform == "typescript" %}
196220

197221
{% tabs %}
198-
{% highlight %}
222+
{% highlight ts tabtitle="app.ts" %}
223+
224+
{% raw %}
199225

200226
document.getElementById('merge_data')?.addEventListener('click', onClickHandler);
201227

@@ -209,6 +235,8 @@ function replacePlaceholders(template: string, data: { [key: string]: string }):
209235
return template.replace(/{{\s*(\w+)\s*}}/g, (match, key) => data[key.trim()] || match);
210236
}
211237

238+
{% endraw %}
239+
212240
{% endhighlight %}
213241
{% endtabs %}
214242

@@ -217,6 +245,8 @@ function replacePlaceholders(template: string, data: { [key: string]: string }):
217245
{% tabs %}
218246
{% highlight js tabtitle="index.js" %}
219247

248+
{% raw %}
249+
220250
var mergeField = document.getElementById('merge_data');
221251
if (mergeField) {
222252
mergeField.addEventListener('click', onClickHandler);
@@ -242,6 +272,8 @@ function replacePlaceholders(template, data) {
242272
});
243273
}
244274

275+
{% endraw %}
276+
245277
{% endhighlight %}
246278
{% endtabs %}
247279
{% endif %}

0 commit comments

Comments
 (0)