Search results

Images in Angular DocumentEditor component

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.

import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import {
    DocumentEditorComponent, EditorService, SelectionService, SfdtExportService, EditorHistoryService, ImageResizerService
} from '@syncfusion/ej2-angular-documenteditor';

    selector: 'app-container',
    template: `<div style="width:100%;height:330px">
    <input id="insertImageButton" #insert_Image_Button style="position:fixed; left:-100em" type="file" (change)="onInsertImage($event)" accept=".jpeg,.jpg,.png,.gif,.bmp">
    <button ejs-button (click)="insertImageButtonClick()" >Insert Image</button>
    <ejs-documenteditor #document_editor  id="container" style="width:100%;height:100%;display:block"  [enableSfdtExport]=true [enableWordExport]=true [enableSelection]=true [enableEditor]=true [isReadOnly]=false [enableImageResizer]=true> </ejs-documenteditor>
    encapsulation: ViewEncapsulation.None,
    providers: [EditorService, SelectionService, SfdtExportService, ImageResizerService]

export class AppComponent {
 public documentEditor: DocumentEditorComponent;

 public insertImageButtonClick() :void {
    let pictureUpload: HTMLInputElement = document.getElementById("insertImageButton") as HTMLInputElement;
    pictureUpload.value = '';;

 public onInsertImage(args: any): void {
    let documentEditor: DocumentEditorComponent =  this.documentEditor;
    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 () {
                   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 =;

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { DocumentEditorAllModule } from '@syncfusion/ej2-angular-documenteditor';
import { AppComponent } from './app.component';

 * Module
    imports: [
    declarations: [AppComponent],
    bootstrap: [AppComponent]
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';


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.

this.documentEditor.selection.imageFormat.width = 800;
this.documentEditor.selection.imageFormat.height = 800;

See Also