Image in EJ2 TypeScript Document editor control

19 Jul 20238 minutes to read

Document Editor supports common raster format images like PNG, BMP, JPEG, SVG and GIF. You can insert an image file or online image in the document using the insertImage() method. Refer to the following sample code.

import { DocumentEditor, Editor, Selection, ImageResizer, EditorHistory } from '@syncfusion/ej2-documenteditor';
import { Button } from '@syncfusion/ej2-buttons';
//Inject require modules.
DocumentEditor.Inject(Editor, Selection, ImageResizer, EditorHistory);
let documenteditor: DocumentEditor = new DocumentEditor({
    isReadOnly: false,
    enableEditor: true,
    enableSection: true,
    enableImageResizer: true,
    enableEditorHistory: true,
    height: '370px'
//Insert Image From URL with alternate text
documenteditor.editor.insertImage('', 200, 200, 'Syncfusion');
let insertPictureButton: Button = new Button();

//Open file picker.
document.getElementById('insert-picture').addEventListener('click', () => {
    let pictureUpload: HTMLInputElement = document.getElementById("insertImageButton") as HTMLInputElement;
    pictureUpload.value = '';;
// File picker change event.
document.getElementById('insertImageButton').addEventListener('change', onInsertImage);

//Get select image from file picker and insert it in Document Editor.
function onInsertImage(args: any): void {
    if (navigator.userAgent.match('Chrome') || navigator.userAgent.match('Firefox') || navigator.userAgent.match('Edge') || navigator.userAgent.match('MSIE') || navigator.userAgent.match('.NET')) {
        if ([0]) {
            let path =[0];
            let reader = new FileReader();
            reader.onload = function (frEvent: any) {
                let base64String =;
                let image = document.createElement('img');
                image.addEventListener('load', function () {
                    //Insert image.
                    documenteditor.editor.insertImage(base64String, this.width, this.height);
                image.src = base64String;
        //Safari does not Support FileReader Class
    } else {
        let image = document.createElement('img');
        image.addEventListener('load', function () {
        image.src =;
<!DOCTYPE html>
<html lang="en">

    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>

    <div id='loader'>Loading....</div>
    <div id='container'>
        <input type="file" id="insertImageButton" style="position:fixed; left:-110em" accept=".jpg,.jpeg,.png,.bmp" />
        <div id='toolbar'>
            <button id="insert-picture">Image</button>
        <div style="width:100%;height: 100%">
            <!--Element which will render as DocumentEditor -->
            <div id="DocumentEditor"></div>



  1. Image files will be internally converted to base64 string. Whereas, online images are preserved as URL. N> 2. EMF and WMF images can’t be inserted, but these types of images will be preserved in Document Editor when using ASP.NET MVC Web API.

Alternate text

Document Editor expose API to get or set the alternate text of the selected image. Refer to the following sample code.

documenteditor.selection.imageFormat.alternateText = 'Adventure Cycle';

Image resizing

Document Editor provides built-in image resizer that can be injected into your application based on the requirements. This allows you to resize the image by dragging the resizing points using mouse or touch interactions. This resizer appears as follows.


Changing size

Document Editor expose API to get or set the size of the selected image. Refer to the following sample code.

documenteditor.selection.imageFormat.width = 800;
documenteditor.selection.imageFormat.height = 800;

Note: Images are stored and processed(read/write) as base64 string in DocumentEditor. The online image URL is preserved as a URL in DocumentEditor upon saving.

Text wrapping style

Text wrapping refers to how images fit with surrounding text in a document. Please refer to this page for more information about text wrapping styles available in Word documents.

Positioning the image

DocumentEditor preserves the position properties of the image and displays the image based on position properties. It does not support modifying the position properties. Whereas the image will be automatically moved along with text edited if it is positioned relative to the line or paragraph.

See Also