Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ layout: post
title: Open document by address in JavaScript (ES5) Docx editor | Syncfusion
description: Learn here all about Open document by address in Syncfusion JavaScript (ES5) Document editor control of Syncfusion Essential JS 2 and more.
platform: document-processing
control: Open document by address
control: Open a Document by Address
documentation: ug
domainurl: ##DomainURL##
---

# Open document by address in JavaScript (ES5) Document editor control

## How to open a document from URL in DocumentEditor
## How to Open a Document from a URL in DocumentEditor

In this article, we are going to see how to open a document from URL in [JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor)
In this article, we are going to see how to open a document from a URL in the [JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor).

please refer below example for client-side code
Please refer to the example below for the client-side code.

```js
//Initialize Document Editor Container component.
// Initialize the Document Editor Container component.
var container = new ej.documenteditor.DocumentEditorContainer();
container.appendTo('#DocumentEditorContainer');
document.getElementById('import').addEventListener('click', function () {
var http = new XMLHttpRequest();
//add your url in which you want to open document inside the ""
// Add the URL from which you want to open the document inside the ""
var content = { fileUrl: "" };
var baseurl = "/api/documenteditor/ImportFileURL";
http.open("POST", baseurl, true);
var baseUrl = "/api/documenteditor/ImportFileURL";
http.open("POST", baseUrl, true);
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
http.onreadystatechange = function () {
if (http.readyState === 4) {
if (http.status === 200 || http.status === 304) {
//open the SFDT text in Document Editor
// Open the SFDT text in the Document Editor
container.documentEditor.open(http.responseText);
}
}
Expand All @@ -39,7 +39,7 @@ document.getElementById('import').addEventListener('click', function () {
});
```

please refer below example for server-side code
Please refer to the example below for the server-side code.

```c#
[AcceptVerbs("Post")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ layout: post
title: Optimize sfdt in JavaScript (ES5) Document editor control | Syncfusion
description: Learn here all about Optimize sfdt in Syncfusion JavaScript (ES5) Document editor control of Syncfusion Essential JS 2 and more.
platform: document-processing
control: Optimize sfdt
control: Optimize SFDT
documentation: ug
domainurl: ##DomainURL##
---

# Optimize sfdt in JavaScript (ES5) Document editor control

Starting from version v21.1.x, the SFDT file generated in Word Processor component is optimized by default to reduce the file size. All static keys are minified, and the final JSON string is compressed. This helps reduce the SFDT file size relative to a DOCX file and provides the following benefits,
* File transfer between client and server through the internet gets faster.
Starting from version v21.1.x, the SFDT file generated in the Document Editor component is optimized by default to reduce the file size. All static keys are minified, and the final JSON string is compressed. This helps reduce the SFDT file size relative to a DOCX file and provides the following benefits:
* File transfer between the client and server through the internet is faster.
* The new optimized SFDT files require less storage space than the old SFDT files.
Hence, the optimized SFDT file can't be directly manipulated as JSON string.

> This feature comes with a public API to switch between the old and new optimized SFDT format, allowing backward compatibility.
Hence, the optimized SFDT file can't be directly manipulated as a JSON string.

As a backward compatibility to create older format SFDT files, refer the following code changes,
N> This feature comes with a public API to switch between the old and new optimized SFDT formats, allowing backward compatibility.

For backward compatibility to create older-format SFDT files, refer to the following code changes:

<table>
<tr>
Expand All @@ -27,14 +28,14 @@ As a backward compatibility to create older format SFDT files, refer the followi
<td>Client-side</td>
<td>
{% tabs %}
{% highlight js tabtitle="Component Declaration"%}
{% highlight js tabtitle="Component Declaration" %}
var documenteditorContainer = new ej.documenteditor.DocumentEditorContainer();
{% endhighlight %}
{% endtabs %}
</td>
<td>
{% tabs %}
{% highlight js tabtitle="Component Declaration"%}
{% highlight js tabtitle="Component Declaration" %}
var documenteditorContainer = new ej.documenteditor.DocumentEditorContainer({ documentEditorSettings: { optimizeSfdt: false } });
{% endhighlight %}
{% endtabs %}
Expand All @@ -44,15 +45,15 @@ var documenteditorContainer = new ej.documenteditor.DocumentEditorContainer({ do
<td>Server-side C#</td>
<td>
{% tabs %}
{% highlight c# tabtitle="Import"%}
{% highlight c# tabtitle="Import" %}
WordDocument sfdtDocument = WordDocument.Load(stream, formatType);
string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(sfdtDocument);
{% endhighlight %}
{% endtabs %}
</td>
<td>
{% tabs %}
{% highlight c# tabtitle="Import"%}
{% highlight c# tabtitle="Import" %}
WordDocument sfdtDocument = WordDocument.Load(stream, formatType);
sfdtDocument.OptimizeSfdt = false;
string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(sfdtDocument);
Expand All @@ -64,14 +65,14 @@ string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(sfdtDocument);
<td>Server-side Java</td>
<td>
{% tabs %}
{% highlight java tabtitle="Import"%}
{% highlight java tabtitle="Import" %}
String sfdtDocument = WordProcessorHelper.load(stream, formatType);
{% endhighlight %}
{% endtabs %}
</td>
<td>
{% tabs %}
{% highlight java tabtitle="Import"%}
{% highlight java tabtitle="Import" %}
String sfdtDocument = WordProcessorHelper.load(stream, formatType, false);
{% endhighlight %}
{% endtabs %}
Expand All @@ -89,7 +90,7 @@ To convert from older format SFDT from a new optimized SFDT file, refer the foll
<td>Client-side</td>
<td>
{% tabs %}
{% highlight js tabtitle="Component Declaration"%}
{% highlight js tabtitle="Component Declaration" %}
var documenteditorContainer = new ej.documenteditor.DocumentEditorContainer({ documentEditorSettings: { optimizeSfdt: false } });
{% endhighlight %}
{% endtabs %}
Expand All @@ -99,7 +100,7 @@ var documenteditorContainer = new ej.documenteditor.DocumentEditorContainer({ do
<td>Server-side C#</td>
<td>
{% tabs %}
{% highlight c# tabtitle="Import"%}
{% highlight c# tabtitle="Import" %}
using(Syncfusion.DocIO.DLS.WordDocument docIODocument = WordDocument.Save(optimizedSfdt)) {
sfdtDocument = WordDocument.Load(docIODocument);
sfdtDocument.OptimizeSfdt = false;
Expand All @@ -113,7 +114,7 @@ using(Syncfusion.DocIO.DLS.WordDocument docIODocument = WordDocument.Save(optimi
<td>Server-side Java</td>
<td>
{% tabs %}
{% highlight java tabtitle="Import"%}
{% highlight java tabtitle="Import" %}
WordDocument docIODocument = WordProcessorHelper.save(optimizedSfdt);
String oldSfdt = WordProcessorHelper.load(docIODocument, false);
{% endhighlight %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ layout: post
title: Override the keyboard shortcuts in JavaScript (ES5) | Syncfusion
description: Learn here all about Override the keyboard shortcuts in Syncfusion JavaScript (ES5) Document editor control of Syncfusion Essential JS 2 and more.
platform: document-processing
control: Override the keyboard shortcuts
control: Override Keyboard Shortcuts
documentation: ug
domainurl: ##DomainURL##
---

# Override the keyboard shortcuts in JavaScript (ES5) Document editor

[JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor) triggers the [`keyDown`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/#keydown) event every time when any key is entered and provides an instance of [`DocumentEditorKeyDownEventArgs`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/documentEditorKeyDownEventArgs/). You can use the [`isHandled`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/documentEditorKeyDownEventArgs/#ishandled) property to override the keyboard shortcut behavior.
[JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor) triggers the [`keyDown`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#keydown) event every time a key is pressed and provides an instance of [`DocumentEditorKeyDownEventArgs`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/documentEditorKeyDownEventArgs) as the event arguments. You can use the [`isHandled`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/documentEditorKeyDownEventArgs#ishandled) property to override the keyboard shortcut behavior.

## Preventing default keyboard shortcut
## Preventing the Default Keyboard Shortcut

The following code shows how to prevent the `CTRL + C` keyboard shortcut for copying selected content in Document Editor.
The following code shows how to prevent the `Ctrl + C` keyboard shortcut for copying selected content in the Document Editor.

{% tabs %}
{% highlight js tabtitle="index.ts" %}
{% highlight js tabtitle="index.js" %}
{% include code-snippet/document-editor/javascript-es5/prevent-keyboard-cs2/index.js %}
{% endhighlight %}
{% highlight html tabtitle="index.html" %}
{% include code-snippet/document-editor/javascript-es5/prevent-keyboard-cs2/index.html %}
{% endhighlight %}
{% endtabs %}

{% previewsample "/document-processing/code-snippet/document-editor/javascript-es5/prevent-keyboard-cs2" %}

## Override or define the keyboard shortcut
## Override or Define the Keyboard Shortcut

Override or define a new keyboard shortcut behavior instead of preventing the keyboard shortcut.

For example, `Ctrl + S` keyboard shortcut saves the document in SFDT format by default, and there is no behavior for `Ctrl + Alt + S`. The following code demonstrates how to override the `Ctrl + S` shortcut to save a document in DOCX format and define `Ctrl + Alt + S` to save the document in SFDT format.
For example, the `Ctrl + S` keyboard shortcut saves the document in SFDT format by default, and there is no behavior for `Ctrl + Alt + S`. The following code demonstrates how to override the `Ctrl + S` shortcut to save a document in DOCX format and define `Ctrl + Alt + S` to save the document in SFDT format.

{% tabs %}
{% highlight js tabtitle="index.ts" %}
{% highlight js tabtitle="index.js" %}
{% include code-snippet/document-editor/javascript-es5/override-keyboard-cs2/index.js %}
{% endhighlight %}
{% highlight html tabtitle="index.html" %}
{% include code-snippet/document-editor/javascript-es5/override-keyboard-cs2/index.html %}
{% endhighlight %}
{% endtabs %}

{% previewsample "/document-processing/code-snippet/document-editor/javascript-es5/override-keyboard-cs2" %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ layout: post
title: Read only default in JavaScript (ES5) Document editor | Syncfusion
description: Learn here all about Read only default in Syncfusion JavaScript (ES5) Document editor control of Syncfusion Essential JS 2 and more.
platform: document-processing
control: Read only default
control: Read-Only by Default
documentation: ug
domainurl: ##DomainURL##
---

# Read only default in JavaScript (ES5) Document editor

In this article, we are going to see how to open a document in read only mode by default in DocumentEditor & DocumentEditorContainer.
In this article, we are going to see how to open a document in read-only mode by default in DocumentEditor and DocumentEditorContainer.

## Opening a document in read only mode by default in DocumentEditor
## Opening a Document in Read-Only Mode by Default in DocumentEditor

{% tabs %}
{% highlight js tabtitle="index.js" %}
Expand All @@ -25,7 +25,7 @@ In this article, we are going to see how to open a document in read only mode by

{% previewsample "/document-processing/code-snippet/document-editor/javascript-es5/read-cs1" %}

## Opening a document in ready only mode by default in DocumentEditorContainer
## Opening a Document in Read-Only Mode by Default in DocumentEditorContainer

{% tabs %}
{% highlight js tabtitle="index.js" %}
Expand All @@ -38,4 +38,4 @@ In this article, we are going to see how to open a document in read only mode by

{% previewsample "/document-processing/code-snippet/document-editor/javascript-es5/read-container-cs1" %}

>Note: You can use the [`restrictEditing`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/#restrictediting) in DocumentEditorContainer and [`isReadOnly`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor/#isreadonly) in DocumentEditor based on your requirement to change component to read only mode.
N> You can use the [`restrictEditing`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#restrictediting) in the DocumentEditorContainer and [`isReadOnly`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#isreadonly) in the DocumentEditor based on your requirement to change the component to read-only mode.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ layout: post
title: Resize document editor in JavaScript (ES5) DOCX editor | Syncfusion
description: Learn here all about Resize document editor in Syncfusion JavaScript (ES5) Document editor control of Syncfusion Essential JS 2 and more.
platform: document-processing
control: Resize document editor
control: Resize Document Editor
documentation: ug
domainurl: ##DomainURL##
---

# Resize document editor in JavaScript (ES5) Document editor control

In this article, we are going to see how to change height and width of [JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor).
In this article, we are going to see how to change the height and width of the [JavaScript DOCX Editor](https://www.syncfusion.com/docx-editor-sdk/javascript-docx-editor) (Document Editor).

## Change height of Document Editor
## Change the Height of the Document Editor

DocumentEditorContainer initially render with default height. You can change height of documenteditor using [`height`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor-container/documentEditorContainerModel#height) property, the value which is in pixel.
The DocumentEditorContainer initially renders with a default height. You can change the height of the DocumentEditor using the [`height`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor-container/documentEditorContainerModel#height) property, the value of which is in pixels.

The following example code illustrates how to change height of Document Editor.
The following example code illustrates how to change the height of the Document Editor.

```js
var container = new ej.documenteditor.DocumentEditorContainer({
Expand All @@ -25,13 +25,13 @@ var container = new ej.documenteditor.DocumentEditorContainer({
container.appendTo('#DocumentEditor');
```

Similarly, you can use [`height`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#height) property for DocumentEditor also.
Similarly, you can also use the [`height`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#height) property for the DocumentEditor.

## Change width of Document Editor
## Change the Width of the Document Editor

DocumentEditorContainer initially render with default width. You can change width of documenteditor using [`width`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor-container/documenteditorcontainermodel#width) property, the value which is in percent.
The DocumentEditorContainer initially renders with a default width. You can change the width of the DocumentEditor using the [`width`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor-container/documentEditorContainerModel#width) property, the value of which is in percentage.

The following example code illustrates how to change width of Document Editor.
The following example code illustrates how to change the width of the Document Editor.

```js
var container = new ej.documenteditor.DocumentEditorContainer({
Expand All @@ -40,13 +40,13 @@ var container = new ej.documenteditor.DocumentEditorContainer({
container.appendTo('#DocumentEditor');
```

Similarly, you can use [`width`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#width) property for DocumentEditor also.
Similarly, you can also use the [`width`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#width) property for the DocumentEditor.

## Resize Document Editor
## Resize the Document Editor

Using [`resize`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#resize) method, you change height and width of Document editor.
Using the [`resize`](https://ej2.syncfusion.com/javascript/documentation/api/document-editor#resize) method, you can change the height and width of the Document Editor.

The following example code illustrates how to fit Document Editor to browser window size.
The following example code illustrates how to fit the Document Editor to the browser window size.

```js
var container = new ej.documenteditor.DocumentEditorContainer({ enableToolbar: true, height: '590px' });
Expand All @@ -58,21 +58,21 @@ container.created = () => {
setInterval(() => {
updateDocumentEditorSize();
}, 100);
//Adds event listener for browser window resize event.
// Adds event listener for browser window resize event.
window.addEventListener('resize', onWindowResize);
};
container.appendTo('#container');

function onWindowResize() {
//Resizes the document editor component to fit full browser window automatically whenever the browser resized.
// Resizes the document editor component to fit full browser window automatically whenever the browser resized.
updateDocumentEditorSize();
}
function updateDocumentEditorSize() {
//Resizes the document editor component to fit full browser window.
// Resizes the document editor component to fit full browser window.
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
container.resize(windowWidth, windowHeight);
}
```

> The Web API hosted link `https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/` utilized in the Document Editor's serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the [GitHub Web Service example](https://github.com/SyncfusionExamples/EJ2-DocumentEditor-WebServices) or [Docker image](https://hub.docker.com/r/syncfusion/word-processor-server) for hosting your own web service and use for the serviceUrl property.
N> The Web API hosted link `https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/` utilized in the Document Editor's serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the [GitHub Web Service example](https://github.com/SyncfusionExamples/EJ2-DocumentEditor-WebServices) or [Docker image](https://hub.docker.com/r/syncfusion/word-processor-server) for hosting your own web service and use for the serviceUrl property.