Server-side Export in JavaScript DOCX Editor

28 Aug 20262 minutes to read

SFDT to DOCX export

DOCX Editor supports server-side export of Syncfusion Document Text (.sfdt) to DOC, DOCX, RTF, TXT, WordML, and HTML formats using the server-side helper component JavaScript DOCX Editor (Document Editor), available with the NuGet packages below for ASP.NET Core, ASP.NET MVC 5, and ASP.NET MVC 4.

Please refer to 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 to the client-side example to serialize the SFDT and send it to the server.

var documenteditor = new ej.documenteditor.DocumentEditor({ enableSfdtExport: true, enableWordExport: true, enableTextExport: true });

documenteditor.appendTo('#DocumentEditor');

// Open the SFDT document.
documenteditor.open(sfdt);

document.getElementById('export').addEventListener('click', function () {
    var http = new XMLHttpRequest();
    http.open('POST', 'http://localhost:5000/api/documenteditor/ExportSFDT');
    http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
    http.responseType = 'json';

    // Serialize document content as SFDT.
    var sfdt = { content: documenteditor.serialize() };

    // Send the SFDT content to server.
    http.send(JSON.stringify(sfdt));
});

NOTE

The DocumentEditor object is available through the DocumentEditorContainer component (DocumentEditor packaged with toolbar, status bar, and properties pane) as documentEditor.