Search results

Server side export in Angular DocumentEditor component

Sfdt to Docx export

Document editor supports server-side export of Syncfusion Document Text (.sfdt) to Doc, Docx, Rtf, Txt, WordML, Html formats using server-side helper Syncfusion.EJ2.DocumentEditor available in ASP.NET Core & ASP.NET MVC platform in the below nugets.

Please refer the following code example.

//API controller for the conversion.
[HttpPost]
public void ExportSFDT([FromBody]SaveParameter data)
{
    Stream document = WordDocument.Save(data.content, FormatType.Docx);
    FileStream file = new FileStream("sample.docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
    document.CopyTo(file);
    file.Close();
    document.Close();
}

public class SaveParameter
{
    public string content { get; set; }
}

Please refer the client side example to serialize the sfdt and send to the server.

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

@Component({
    selector: 'app-container',
    template: `<div style="width:100%;height:330px"><button ejs-button (click)="saveAsSfdt()" >Export SFDT</button>
    <ejs-documenteditor #document_editor  id="container" style="width:100%;height:100%;display:block" [isReadOnly]=false [enableEditor]=true [enableWordExport]=true [enableSfdtExport]=true> </ejs-documenteditor></div>`,
    encapsulation: ViewEncapsulation.None,
    providers: [EditorService, SelectionService, SfdtExportService,TextExportService]
})

export class AppComponent {
 @ViewChild('document_editor')
 public documentEditor: DocumentEditorComponent;

 public saveAsSfdt() :void {
    let http: XMLHttpRequest = new XMLHttpRequest();
    http.open('POST', 'http://localhost:5000/api/documenteditor/ExportSFDT');
    http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
    http.responseType = 'json';
    let sfdt: any = { content: container.documentEditor.serialize() };
    http.send(JSON.stringify(sfdt));
    });
 }

DocumentEditor object is available in DocumentEditorContainer component(DocumentEditor packaged with toolbar, statusbar & properties pane) as documentEditor