HTML in to document editor

Hello,

I just wondered if it was possible to convert HTML to SFDT and vice versa for use in the DocumentEditor component. I'm currently messing about with this: https://www.nuget.org/packages/Syncfusion.EJ2.WordEditor.AspNet.Core but haven't really figured out an answer so far.

Thanks!

Tim

1 Reply 1 reply marked as answer

AE Ajithamarlin Edward Syncfusion Team July 9, 2020 03:12 PM UTC

Hi Tim,  
  
  
In DocumentEditor, you can open and save html file using Syncfusion Docio library. So, we need to write server side WebAPI either in Asp.Net MVC or Core to achieve your requirement. To open html file, we need to use Syncfusion.Docio library to convert the stream to document editor internal structure. Then convert the internal structure to json. Finally, open that json in document editor.   
  
  
Sample code snippet to open html in document editor. 
  
  
        [AcceptVerbs("Post")] 
        [HttpPost] 
        [Route("ImportHtmlToDoc")] 
        public string ImportHtmlToDoc(IFormCollection data) 
        { 
  
            Stream stream = new MemoryStream(); 
            IFormFile file = data.Files[0]; 
            file.CopyTo(stream); 
            stream.Position = 0; 
  
            //Loads the HTML document against transitional schema validation 
  
            Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(stream,Syncfusion.DocIO.FormatType.Html); 
  
            MemoryStream outputStream = new MemoryStream(); 
            //Saves the Word document 
  
            document.Save(outputStream, Syncfusion.DocIO.FormatType.Docx); 
  
            //Closes the document 
  
  
            // Write Pdf stream here.              
            EJ2WordDocument wdocument = EJ2WordDocument.Load(outputStream, GetFormatType("docx")); 
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(wdocument); 
            wdocument.Dispose(); 
            return json; 
        } 
  
  
Sample code snippet to save as html in document editor. 
  
  
[AcceptVerbs("Post")] 
        [HttpPost] 
        [Route("DocToHtml")] 
        public IActionResult DocToHtml(IFormCollection data) 
        { 
            Stream stream = new MemoryStream(); 
            IFormFile file = data.Files[0]; 
            file.CopyTo(stream); 
            stream.Position = 0; 
            Syncfusion.DocIO.DLS.WordDocument wordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);             
            //Saves the html file 
            wordDocument.Save(stream,Syncfusion.DocIO.FormatType.Html); 
            stream.Position = 0; 
            return File(stream, "application/html", "WordToHTML.html");             
        } 
  
  
You can pass the document editor content from document editor as blob to above sample code snippets in server-side. 
  
  
  
  
kindly check it and please let us know if you need any further assistance on this. 
  
Regards, 
Ajithamarlin E. 


Marked as answer
Loader.
Up arrow icon