Hi
Out scenario is as follow - we have a C++ server which loads an RTF document from a database. We then want to be able to edit the document on a JavaScript web client using DocumentEditor, and then save it back to the database in doc form.
I am thinking of creating an ASP.NET Core executable that converts an RTF to SFDT and vice versa. My C++ code can then extract the doc from the DB, dump it to a file, use a shell command to convert it to an SFDT and send it to the client and then do the same in reverse on save. IT may end up a bit slow but we're ok with that ATM.
Questions
- Is this a good/possible solution ?
- Does such an exe already exist for download ?
- If not, can you please provide minimal C# code to convert from RTF to SFDT and back for me to use ?
Thanks!
Hi Micha,
You are using a C++ server to load an RTF document from the database. Instead, you can directly use the ASP.NET core to extract the document from the database connection. In this case, we avoid the C++ server and straight away use the ASP.NET core to dump the file. And also, we have the support to save a document in RTF file format.
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 in ASP.NET Core.
Documentation Links:
https://ej2.syncfusion.com/documentation/document-editor/import
https://ej2.syncfusion.com/documentation/document-editor/saving-documents/server-side-export
Please refer the following code example to save the document.
//API controller for the conversion.
[HttpPost]
public void ExportSFDT([FromBody]SaveParameter data)
{
Stream document = WordDocument.Save(data.content, FormatType.Rtf);
FileStream file = new FileStream("sample.rtf", 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 { DocumentEditor, FormatType, WordExport, SfdtExport } from '@syncfusion/ej2-documenteditor';
//Inject require modules.
DocumentEditor.Inject(WordExport, SfdtExport);
let documenteditor: DocumentEditor = new DocumentEditor({ enableSfdtExport: true, enableWordExport: true, enableTextExport: true });
documenteditor.appendTo('#DocumentEditor');
//Open the sfdt document.documenteditor.open(sfdt);
document.getElementById('export').addEventListener('click', () => {
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';
//Serialize document content as SFDT.
let sfdt: any = { content: documenteditor.serialize() };//Send the sfdt content to server side.
http.send(JSON.stringify(sfdt));
});Regards,
Balamurugan S
Thanks Balamurugan !
The web client authenticates via our C++ server and we cannot reauthenticate them to a .NET app as that will entail duplicating the user management system which we cannot do.
I hope that makes sense ?
Regards
Micha
Hi Micha,
Thanks for the update.
If your requirement is a C++ server, then you can use your own way. And we shared a SFDT to RTF conversion in the previous update.
Please refer the previous update to save the document.
With the above-mentioned code, we have saved the rtf document in fileStream. If you need it, you can change this filestream based on the communicating C++ server.
Regards,
Balamurugan S