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 @@ -10,7 +10,7 @@ domainurl: ##DomainURL##

# Java in JavaScript (ES5) Document editor control

This page illustrates how to create web service in Java for the server-side dependent functionalities of Word Processor component a.k.a. Document Editor. Document Editor depends on server side interaction for below listed operations and it can be written in Java using `syncfusion-ej2-wordprocessor.jar` file.
This page illustrates how to create a web service in Java for the server-side dependent functionalities of the Word Processor component (a.k.a. Document Editor). Document Editor depends on server-side interaction for the operations listed below, and it can be written in Java using the `syncfusion-ej2-wordprocessor.jar` file.

* Import Word Document
* Paste with formatting
Expand All @@ -20,7 +20,7 @@ This page illustrates how to create web service in Java for the server-side depe

## Supported Java versions

Syncfusion<sup style="font-size:70%">&reg;</sup> Java library supports Java SE 8.0(1.8) or above versions.
Syncfusion<sup style="font-size:70%">&reg;</sup> Java library supports Java SE 8.0 (1.8) or above.

## External Jars Required

Expand Down Expand Up @@ -109,11 +109,11 @@ This section explains how to create the Java web service for DocumentEditor.

## Importing Word Document

As the Document editor client-side script requires the document in SFDT file format, you can convert the Word documents (.dotx,.docx,.docm), rich text format documents (.rtf), and text documents (.txt) into SFDT format by using this Web API.
As the Document Editor client-side script requires the document in SFDT file format, you can convert the Word documents (.dotx, .docx, .docm), rich text format documents (.rtf), and text documents (.txt) into SFDT format by using this Web API.

Note: Document editor Java library doesn’t have support for the **DOC format** Word document. As the DOC format is an older file format, we are concentrating on latest DOCX specific features and it will be more helpful in future if you use DOCX format to utilize some more features from Document editor. So, we recommend you to use the DOCX file format instead of DOC file format, to achieve your requirement.
N> The Document Editor Java library does not support the **DOC format** Word document. As the DOC format is an older file format, Syncfusion is concentrating on the latest DOCX-specific features, which will be more helpful in the future. Using the DOCX format allows you to utilize more features from Document Editor. Therefore, we recommend using the DOCX file format instead of the DOC file format to achieve your requirement.

The following example code illustrates how to write a Web API for importing Word documents into Document Editor component.
The following example code illustrates how to write a Web API for importing Word documents into the Document Editor component.

```java
@CrossOrigin(origins = "*", allowedHeaders = "*")
Expand All @@ -128,13 +128,13 @@ The following example code illustrates how to write a Web API for importing Word
}
```

### Import document with TIFF, EMF and WMF images
### Import document with TIFF, EMF, and WMF images

The web browsers do not support to display metafile images like EMF and WMF and also TIFF format images. As a fallback approach, you can convert the metafile/TIFF format image to raster image using any image converter in the `MetafileImageParsed` event and this fallback raster image will be displayed in the client-side Document editor component.
The web browsers do not support displaying metafile images like EMF and WMF, and also TIFF format images. As a fallback approach, you can convert the metafile/TIFF format image to a raster image using any image converter in the `MetafileImageParsed` event, and this fallback raster image will be displayed in the client-side Document Editor component.

>Note: In `MetafileImageParsedEventArgs` event argument, you can get the metafile stream using `getMetafileStream()` property and you can get the `getIsMetafile()` boolean value to determine whether the image is meta file images(WMF,EMF) or TIFF format images. In below example, we have converted the TIFF to raster image in `ConvertTiffToRasterImage()` method using TwelveMonkeys ImageIO TIFF library.
N> In the `MetafileImageParsedEventArgs` event argument, you can get the metafile stream using the `getMetafileStream()` property, and you can get the `getIsMetafile()` boolean value to determine whether the image is a metafile image (WMF, EMF) or a TIFF format image. In the example below, the TIFF is converted to a raster image in the `ConvertTiffToRasterImage()` method using the TwelveMonkeys ImageIO TIFF library.

The following example code illustrates how to use `MetafileImageParsed` event for creating fallback raster image for metafile present in a Word document.
The following example code illustrates how to use the `MetafileImageParsed` event for creating a fallback raster image for a metafile present in a Word document.

```java
import com.syncfusion.javahelper.system.collections.generic.*;
Expand Down Expand Up @@ -180,11 +180,11 @@ import com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi;
delegateList.remove(delegate);
}
};
// Hooks MetafileImageParsed event.
// Hooks the MetafileImageParsed event.
WordProcessorHelper.MetafileImageParsed.add("OnMetafileImageParsed", metafileImageParsedEvent);
// Converts DocIO DOM to SFDT DOM.
String sfdtContent = WordProcessorHelper.load(docIoDocument);
// Unhooks MetafileImageParsed event.
// Unhooks the MetafileImageParsed event.
WordProcessorHelper.MetafileImageParsed.remove("OnMetafileImageParsed", metafileImageParsedEvent);
return sfdtContent;
} catch (Exception e) {
Expand All @@ -193,17 +193,17 @@ import com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi;
}
}

// Converts Metafile to raster image.
// Converts a metafile to a raster image.
private static void OnMetafileImageParsed(Object sender, MetafileImageParsedEventArgs args) {
if (args.getIsMetafile())
{
//MetaFile image conversion(EMF and WMF)
//You can write your own method definition for converting metafile to raster image using any third-party image converter.
// Metafile image conversion (EMF and WMF)
// You can write your own method definition for converting a metafile to a raster image using any third-party image converter.
args.setImageStream(ConvertMetafileToRasterImage(args.getMetafileStream())) ;
}
else
{
//TIFF image conversion
// TIFF image conversion
args.setImageStream(ConvertTiffToRasterImage(args.getMetafileStream())) ;
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ import com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderSpi;

## Paste with formatting

This Web API converts the system clipboard data (HTML/RTF) to SFDT format which is required to paste content with formatting.
This Web API converts the system clipboard data (HTML/RTF) to SFDT format, which is required to paste content with formatting.

The following example code illustrates how to write a Web API for paste with formatting.

Expand Down Expand Up @@ -285,11 +285,11 @@ The following example code illustrates how to write a Web API for paste with for
delegateList.remove(delegate);
}
};
// Hooks MetafileImageParsed event.
// Hooks the MetafileImageParsed event.
WordProcessorHelper.MetafileImageParsed.add("OnMetafileImageParsed", metafileImageParsedEvent);
// Converts Clipboard content to SFDT DOM.
String sfdtContent = WordProcessorHelper.loadString(param.content, GetFormatType(param.type.toLowerCase()));
// Unhooks MetafileImageParsed event.
// Unhooks the MetafileImageParsed event.
WordProcessorHelper.MetafileImageParsed.remove("OnMetafileImageParsed", metafileImageParsedEvent);
return sfdtContent;
} catch (Exception e) {
Expand All @@ -316,19 +316,19 @@ The following example code illustrates how to write a Web API for paste with for
}
}

// Converts Metafile to raster image.
// Converts a metafile to a raster image.
private static void OnMetafileImageParsed(Object sender, MetafileImageParsedEventArgs args) {
// You can write your own method definition for converting metafile to raster
// You can write your own method definition for converting a metafile to a raster
// image using any third-party image converter.
args.setImageStream(ConvertMetafileToRasterImage(args.getMetafileStream())) ;
}
```

>Note: The web browsers do not support to display metafile images like EMF and WMF. As a fallback approach, you can convert the metafile to raster image using any image converter in the `MetafileImageParsed` event and this fallback raster image will be displayed in the client-side Document editor component.
N> The web browsers do not support displaying metafile images like EMF and WMF. As a fallback approach, you can convert the metafile to a raster image using any image converter in the `MetafileImageParsed` event, and this fallback raster image will be displayed in the client-side Document Editor component.

## Restrict editing
## Restrict Editing

This Web API generates hash from the specified password and salt value which is required for restrict editing functionality of Document Editor component.
This Web API generates a hash from the specified password and salt value, which is required for the restrict editing functionality of the Document Editor component.

The following example code illustrates how to write a Web API for restrict editing.

Expand Down Expand Up @@ -375,11 +375,11 @@ The following example code illustrates how to write a Web API for restrict editi

## Spell Check

Document Editor supports performing spell checking for any input text. You can perform spell checking for the text in Document Editor and it will provide suggestions for the mis-spelled words through dialog and in context menu. Document editor client-side script requires this Web API to show error words and list suggestions in context menu. This Web API returns the json type of spell-checked word which contains details about error words if any and suggestions.
Document Editor supports performing spell checking for any input text. You can perform spell checking for the text in Document Editor, and it will provide suggestions for the misspelled words through a dialog and the context menu. The Document Editor client-side script requires this Web API to show error words and list suggestions in the context menu. This Web API returns the JSON type of spell-checked word, which contains details about error words, if any, and suggestions.

To know more about configure spell check, please check this [link](https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/tree/master/Java#steps-to-configure-spell-checker).
To know more about configuring spell check, please refer to this [link](https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/tree/master/Java#steps-to-configure-spell-checker).

In controller file, you can configure the spell check files like below:
In the controller file, you can configure the spell check files as shown below:

```java
List<DictionaryData> spellDictionary;
Expand All @@ -396,8 +396,8 @@ In controller file, you can configure the spell check files like below:
JsonObject spellCheckerInfo = spellDictionaryItems.get(i).getAsJsonObject();
DictionaryData dict = new DictionaryData();

if(spellCheckerInfo.has("LanguadeID"))
dict.setLanguadeID(spellCheckerInfo.get("LanguadeID").getAsInt());
if(spellCheckerInfo.has("LanguageID"))
dict.setLanguageID(spellCheckerInfo.get("LanguageID").getAsInt());
if(spellCheckerInfo.has("DictionaryPath"))
dict.setDictionaryPath("src/main/resources/"+spellCheckerInfo.get("DictionaryPath").getAsString());
if(spellCheckerInfo.has("AffixPath"))
Expand All @@ -408,11 +408,11 @@ In controller file, you can configure the spell check files like below:
}
```

Document editor provides options to spell check word by word and spellcheck page by page when loading the documents.
Document Editor provides options to spell check word by word and spell check page by page when loading the documents.

### Spell check word by word

This Web API performs the spell check word by word and return the json which contains information about error words and suggestions if any. By default, spell check word by word is performed in Document editor when enabling spell check in client-side.
This Web API performs the spell check word by word and returns the JSON, which contains information about error words and suggestions, if any. By default, spell check word by word is performed in Document Editor when enabling spell check on the client side.

The following example code illustrates how to write a Web API for spell check word by word.

Expand Down Expand Up @@ -448,7 +448,7 @@ The following example code illustrates how to write a Web API for spell check wo

### Spell check page by page

This Web API performs the spell check page by page and return the json which contains information about error words and suggestions if any. By [enabling optimized spell check](../spell-check#enableoptimizedspellcheck) in client-side, you can perform spellcheck page by page when loading the documents.
This Web API performs the spell check page by page and returns the JSON, which contains information about error words and suggestions, if any. By [enabling optimized spell check](../spell-check#enableoptimizedspellcheck) on the client side, you can perform spell check page by page when loading the documents.

The following example code illustrates how to write a Web API for spell check page by page.

Expand Down Expand Up @@ -484,13 +484,13 @@ The following example code illustrates how to write a Web API for spell check pa

## Save as file formats other than SFDT and DOCX

You can configure this API, if you want to save the document in file format other than DOCX and SFDT using server-side. You can save the document in following ways:
You can configure this API if you want to save the document in a file format other than DOCX and SFDT on the server side. You can save the document in the following ways:

### Save the document in database or file server
### Save the document in a database or file server

This Web API saves the document in the server machine. You can customize this API to save the document into databases or file servers.

The following example code illustrates how to write a Web API for save document in server-side.
The following example code illustrates how to write a Web API to save a document on the server side.

```c#
@CrossOrigin(origins = "*", allowedHeaders = "*")
Expand All @@ -503,7 +503,7 @@ The following example code illustrates how to write a Web API for save document
name = "Document1.docx";
}
WordDocument document = WordProcessorHelper.save(data.getContent());
// Saves the document to server machine file system, you can customize here to save into databases or file servers based on requirement.
// Saves the document to the server machine file system; you can customize this to save into databases or file servers based on your requirement.
FileOutputStream fileStream = new FileOutputStream(name);
document.save(fileStream, getWFormatType(format));
fileStream.close();
Expand Down Expand Up @@ -562,11 +562,11 @@ The following example code illustrates how to write a Web API for save document
}
```

### Save as other file formats by passing SFDT string
### Save as other file formats by passing an SFDT string

This Web API converts the SFDT string to required format and returns the document as FileStreamResult to client-side. Using this API, you can save the document in file format other than SFDT and DOCX and download the document in client browser.
This Web API converts the SFDT string to the required format and returns the document as a FileStreamResult to the client side. Using this API, you can save the document in a file format other than SFDT and DOCX and download the document in the client browser.

The following example code illustrates how to write a Web API for export sfdt.
The following example code illustrates how to write a Web API to export SFDT.

```c#
@CrossOrigin(origins = "*", allowedHeaders = "*")
Expand Down Expand Up @@ -637,9 +637,9 @@ The following example code illustrates how to write a Web API for export sfdt.
}
```

### Save as other file formats by passing DOCX file
### Save as other file formats by passing a DOCX file

This Web API converts the DOCX document to required format and returns the document as FileStreamResult to client-side. Using this API, you can save the document in file format other than SFDT and DOCX and download the document in client browser.
This Web API converts the DOCX document to the required format and returns the document as a FileStreamResult to the client side. Using this API, you can save the document in a file format other than SFDT and DOCX and download the document in the client browser.

The following example code illustrates how to write a Web API for export.

Expand Down Expand Up @@ -688,4 +688,4 @@ The following example code illustrates how to write a Web API for export.
}
```

>Note: Please refer the [Java Web API example from GitHub](https://github.com/SyncfusionExamples/EJ2-DocumentEditor-WebServices/tree/master/Java).
N> Please refer to the [Java Web API example from GitHub](https://github.com/SyncfusionExamples/EJ2-DocumentEditor-WebServices/tree/master/Java).
Loading