Skip to content

954365: Added how to compare sfdt #4167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: hotfix/hotfix-v29.1.33
Choose a base branch
from
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
@@ -0,0 +1,5 @@
public ActionResult Default()
{
return View();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

@Html.EJS().Button("element").Content("Compare SFDT").Click("compare").Render()
@Html.EJS().DocumentEditorContainer("container").Created("onCreated").EnableToolbar(true).Render()

<script>
var documenteditor;
var container;
function onCreated() {
var documenteditorElement = document.getElementById("container");
container = documenteditorElement.ej2_instances[0];
documenteditor = container.documentEditor;
}
//Compare SFDT
function compare() {
let url = 'http://localhost:62869/api/documenteditor/Compare';
let http = new XMLHttpRequest();
http.open('POST', url);
http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
// http.responseType = 'json';
http.onreadystatechange = () => {
if (http.readyState === 4) {
if (http.status === 200 || http.status === 304) {
container.documentEditor.open(
http.response
);
}
}
};

http.send();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="control-section">
<ejs-button id="element" content="Compare SFDT" onclick="compare()"></ejs-button>

<ejs-documenteditorcontainer id="container" serviceUrl="/api/DocumentEditor/" enableToolbar=true created="onCreated" height="590px"></ejs-documenteditorcontainer>
</div>
<script>
var documenteditor;
var container;
function onCreated() {
var documenteditorElement = document.getElementById("container");
container = documenteditorElement.ej2_instances[0];
documenteditor = container.documentEditor;
}
//Compare SFDT
function compare() {
let url = 'http://localhost:62869/api/documenteditor/Compare';
let http = new XMLHttpRequest();
http.open('POST', url);
http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
// http.responseType = 'json';
http.onreadystatechange = () => {
if (http.readyState === 4) {
if (http.status === 200 || http.status === 304) {
container.documentEditor.open(
http.response
);
}
}
};

http.send();
}
</script>
80 changes: 80 additions & 0 deletions ej2-asp-core-mvc/document-editor/how-to/compare-sfdt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
layout: post
title: Compare sfdt in Syncfusion ##Platform_Name## Document Editor Component
description: Learn here all about how to Compare sfdt in Syncfusion ##Platform_Name## Document Editor component of Syncfusion Essential JS 2 and more.
platform: ej2-asp-core-mvc
control: Compare sfdt
publishingplatform: ##Platform_Name##
documentation: ug
---

# How to Compare sfdt in ##Platform_Name## Document editor control

## Compare sfdt in server-side using Syncfusion DocIO

The Document Editor doesn't provide support for comparing documents on the client side. We can achieve this requirement using the Syncfusion DocIO library on the server side.
We have prepared a sample for comparing two Sfdt documents.

With the help of [`Syncfusion DocIO`](https://help.syncfusion.com/document-processing/word/word-library/net/word-document/compare-word-documents), you can compare existing documents or documents created from scratch using the Compare method in the .NET Word library (DocIO) on the server side.

The following way illustrates how to Compare Document:

The following example code illustrates how to compare the document to call the Compare Web API from server side in client side code.

{% if page.publishingplatform == "aspnet-core" %}

{% tabs %}
{% highlight cshtml tabtitle="CSHTML" %}
{% include code-snippet/document-editor-container/compare-sfdt/tagHelper %}
{% endhighlight %}
{% highlight c# tabtitle="Compare-sfdt.cs" %}
{% endhighlight %}{% endtabs %}

{% elsif page.publishingplatform == "aspnet-mvc" %}

{% tabs %}
{% highlight razor tabtitle="CSHTML" %}
{% include code-snippet/document-editor-container/compare-sfdt/razor %}
{% endhighlight %}
{% highlight c# tabtitle="Compare-sfdt.cs" %}
{% endhighlight %}{% endtabs %}
{% endif %}


* Using Compare web API in server-side, you can Copare the documents.
* We compare the two different documents using docIO compare API and store the result to the Original document.
Save the document to stream and pass it to EJ2 document editor load API to get the Sfdt string.
The resulting document will be opened on the client side.
* Finally, the compared document will shown in Document Editor User interface (UI).

The following example code illustrates how to compare Documents in server-side.

```csharp
[AcceptVerbs("Post")]
[HttpPost]
[EnableCors("AllowAllOrigins")]
[Route("Compare")]
public string Compare([FromBody] SaveParameter data)
{
string sfdtText = "";
using (WDocument originalDocument = WordDocument.Save(data.Content))
{
using (WDocument revisedDocument = WordDocument.Save(data.Content))
{
// Compare the original and revised Word documents.
originalDocument.Compare(revisedDocument);

//Save the Word document to MemoryStream
MemoryStream stream = new MemoryStream();
originalDocument.Save(stream, WFormatType.Docx);
stream.Position = 0;

WordDocument document = WordDocument.Load(stream, FormatType.Docx);
sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
}

}
return sfdtText;
}
```
1 change: 1 addition & 0 deletions ej2-asp-core-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@
<li><a href="/ej2-asp-core/document-editor/how-to/change-the-default-search-highlight-color">Change the default search highlight color</a></li>
<li><a href="/ej2-asp-core/document-editor/how-to/optimize-sfdt">Optimize the SFDT file</a></li>
<li><a href="/ej2-asp-core/document-editor/how-to/enable-ruler-in-document-editor-component">Enable ruler in Document Editor component</a></li>
<li><a href="ej2-asp-core/document-editor/how-to/compare-sfdt">Compare SFDT</a></li>
</ul>
</li>
<li>FAQ
Expand Down
1 change: 1 addition & 0 deletions ej2-asp-mvc-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@
<li><a href="/ej2-asp-mvc/document-editor/how-to/change-the-default-search-highlight-color">Change the default search highlight color</a></li>
<li><a href="/ej2-asp-mvc/document-editor/how-to/optimize-sfdt">Optimize the SFDT file</a></li>
<li><a href="/ej2-asp-mvc/document-editor/how-to/enable-ruler-in-document-editor-component">Enable ruler in Document Editor component</a></li>
<li><a href="/ej2-asp-mvc/document-editor/how-to/compare-sfdt">Compare SFDT</a></li>
</ul>
</li>
<li>FAQ
Expand Down