Search results

Images in ASP.NET Core DocumentEditor control

08 Apr 2021 / 1 minute to read

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

Copied to clipboard
<input type="file" id="insertImageButton" style="position:fixed; left:-110em" accept=".jpg,.jpeg,.png,.bmp" />
<ejs-button id="insert_picture">Image</ejs-button>
<div id="documenteditor" style="width:100%;height:100%" >
<ejs-documenteditor isReadOnly=false enableEditor=true enableSelection=true enableImageResizer=true enableEditorHistory=true id="container"></ejs-documenteditor>

    var documenteditor;
    document.addEventListener('DOMContentLoaded', function () {
        documenteditor = document.getElementById("container").ej2_instances[0];
        document.getElementById('insert-picture').addEventListener('click', function () {
            var pictureUpload = document.getElementById("insertImageButton");
            pictureUpload.value = '';
        document.getElementById('insertImageButton').addEventListener('change', onInsertImage);
        function onInsertImage(args) {
            if (navigator.userAgent.match('Chrome') || navigator.userAgent.match('Firefox') || navigator.userAgent.match('Edge') || navigator.userAgent.match('MSIE') || navigator.userAgent.match('.NET')) {
                if ([0]) {
                    var path =[0];
                    var reader = new FileReader();
                    reader.onload = function (frEvent) {
                        var base64String =;
                        var image = document.createElement('img');
                        image.addEventListener('load', function () {
                            documenteditor.editor.insertImage(base64String, this.width, this.height);
                        image.src = base64String;
                //Safari does not Support FileReader Class
            } else {
                var image = document.createElement('img');
                image.addEventListener('load', function () {
                image.src =;


Image files will be internally converted to base64 string. Whereas, online images are preserved as URL.

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.

Copied to clipboard
documenteditor.selection.imageFormat.width = 800;
documenteditor.selection.imageFormat.height = 800;

See Also