DocumentEditor from json string and converting document to HTML format



I have other requirements. Can you help me out on this or any other alternative is appreciated,
1) Requirement: Sending document content in the email body without changing the styles and document content.

Can we convert Document to pure HTML. So, that I can use this HTMLto send in Email body with the same format.


2) Can we load the document from json string. That was created from the following code 

           WordDocument document = WordDocument.Load(processTuple.Item1, GetFormatType(processTuple.Item2.ToLower()));
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);

I will be saving the above json in database. In a new request, after fetching the data from database in server side, I will modifying some styles and content and convert back to HTML format. 

1 Reply

SM Suriya Murugan Syncfusion Team September 12, 2019 10:56 AM UTC

Hi Naren, 
 
Thank you for contacting the Syncfusion support. 
 
Can we convert Document to pure HTML. So, that I can use this HTMLto send in Email body with the same format. 
  
Yes, you can convert the document to pure HTML using Syncfusion DocIO library. Then pass the converted html to email body. 
  
Client side in below sample code check exportAsHtml method: 
  
  
  
Server side sample code: 
  
public string 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; 
  
//Now, converting the stream to string  
StreamReader reader = new StreamReader( stream ); 
string text = reader.ReadToEnd(); 
// Now, you set this html string to email body 
return text;             
  
  
For your convenienet we have prepared sample, kindly check it in below link: 
  
  
Please let me know if you have any concerns. 
  
  
  
Can we load the document from json string. 
In backend, it is not possible to convert the json string to document.
  
In client side, using saveAsBlob you can convert the save the document as Docx option and get is as a blob stream and then pass that stream to server. Then proceed further for your requirement. 
  
Open the sfdt in DocumentEditor using open method and then save it using saveAsBlob method. 
  
Sample link: 
  
 
Please let me know if you have any concerns. 
 
Regards, 
 
Suriya M. 
 


Loader.
Up arrow icon