Converting SFDT to DOCX - Server Side

I'm trying to convert the sfdt to docx on the backend by sending a request to syncfusion like so:

def convert_sfdt_to_docx(file):
    try:
        api_url = "https://ej2services.syncfusion.com/production/web-services/api/documenteditor/ExportSFDT"
        payload = {
            "content": file,
            "format": "Docx",
        }
        # Set the headers including the Syncfusion license key
        headers = {
            "Content-Type": "application/json",
        }
        response = requests.post(api_url, json=payload, headers=headers)
        print(response['content'])
    except Exception as e:
        print("Could not open the document")
        return None

And I'm getting "Could not open the document" with an error 500
If anyone knows how to do that on the backend I would be glad

1 Reply

KM Kavitha Muralitharan Syncfusion Team September 23, 2024 08:23 AM UTC

Hi Noam Azoulay,


We have shared a UG Documentation for server-side export along with the sample and video.
Please refer to it and let us know if you need any other assistance.


Code Snippet:

Client-Side:
function save() {
            let http = new XMLHttpRequest();


            http.open('POST', 'http://localhost:62869/api/documenteditor/ExportSFDTDoc');


            http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');


            http.responseType = 'json';    //Serialize document content as SFDT.
            let sfdt = { content: container.current.documentEditor.serialize() };


            //Send the sfdt content to server side.  


            http.send(JSON.stringify(sfdt));
        }

Server-Side:

 [AcceptVerbs("Post")]

 [HttpPost]

 [EnableCors("AllowAllOrigins")]

 [Route("ExportSFDTDoc")]

 public void ExportSFDTDoc([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();

 }




UG Documentation: https://ej2.syncfusion.com/react/documentation/document-editor/saving-documents/server-side-export

Sample: https://stackblitz.com/edit/react-nkjn4s-dwlp9w?file=index.js,index.html



Regards,

Kavitha M


Attachment: Sample_and_Video_1c318ccc.zip

Loader.
Up arrow icon