The given key 'sfdt' was not present in the dictionary

I am following  code samples in this link - https://ej2.syncfusion.com/documentation/document-editor/saving-documents/server-side-export

But I am getting below error

System.Collections.Generic.KeyNotFoundException: 'The given key 'sfdt' was not present in the dictionary.'


My payload for post call is -

{

  "content": "{\"sections\":[{\"blocks\":[{\"inlines\":[{\"characterFormat\":{\"bold\":true,\"italic\":true},\"text\":\"Hello World\"}]}],\"headersFooters\":{}}]}"

}


I have created sample application . there too I get same error . Sample code is this git repo - 

https://github.com/kuntadynithesh/SyncDocTest 


may I know whats wrong with code here ? Am I missing something ?


9 Replies

SI Suresh Iyappan Syncfusion Team August 23, 2024 06:27 PM UTC

Hi Nithesh,

It seems that your payload to endpoint is using the unoptimized form of SFDT structure. We suggest you to convert the contents into optimize SFDT structure and let us know if you face any further issues. Please refer to the provided documentation link on how to optimize the SFDT structure.
https://ej2.syncfusion.com/aspnetcore/documentation/document-editor/how-to/optimize-sfdt 


Regards,
Suresh I



KN Kuntady Nithesh August 27, 2024 02:48 PM UTC

Can you share a sample solution if you have . I am finding it hard to create one with optimized sfdt structure 



KD Kesavan D Syncfusion Team August 29, 2024 06:35 PM UTC

Hi Nithesh,

Manual creation of SFDT file is not recommended. Document Editor have API to export to SFDT file for the document content that is currently visible in the editor. We suspect there is a misunderstanding on the SFDT file structure or the use case which you are trying is different. If yes, we could connect over a call to discuss about this. Please feel free to create a ticket in our support system.

Additionally, the SFDT which you are trying a very minimal SFDT which has only simple text and SFDT is complex structure which nested key and objects. Normally the input Word document are converted to SFDT using the server-side Core in EJ2 TypeScript Document editor control | Syncfusion and client-side opens the SFDT for rendering.

WordDocument document = WordDocument.Load(stream, FormatType.Docx);

string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);

document.Dispose();

return json;


The previously provided documentation is how to make the Document Editor generate SFDT in optimized and unoptimized mode. From version v21.1.x, the SFDT file generated in the Document Editor component is optimized by default to reduce the file size. All static keys are minified, and the final JSON string is compressed. This helps reduce the SFDT file size relative to a DOCX file.

UG: Optimize sfdt in EJ2 TypeScript Document editor control | Syncfusion 


Regards,

Kesavan.


CC Christian Casal August 30, 2024 01:26 PM UTC

could we please have a sample of angular document editor sending content to c# backend and save it as a docx format? and also sending it back to the front end editor.



SI Suresh Iyappan Syncfusion Team September 2, 2024 04:58 PM UTC

Hi Christian Casal,

Please find the attached angular sample link, and the web services project which contains the API endpoints and the demo video in the Zip file.

Sample link: https://stackblitz.com/edit/angular-z5wqbm-rsmjdi?file=src%2Fapp.component.html,src%2Fapp.component.ts


Regards,
Suresh I


Attachment: Demo_d56d809f.zip


KN Kuntady Nithesh October 15, 2024 07:11 PM UTC

We successfully created a DOCX file from an optimized SFDT string. However, when I try to convert that saved DOCX file back into an SFDT format, the resulting SFDT is incorrect and doesn't represent the entire document. I've created a sample for this, with two APIs:


ExportSFDT (POST): This creates a DOCX file from the given SFDT string, and it works perfectly, generating the file locally.

LoadSFDT (GET): Here, I'm trying to convert the DOCX file back into an SFDT string and save it as another DOCX file to verify that the extracted SFDT is correct. However, the process fails because the resulting SFDT is not accurate.

Could you please review the code and help identify what might be going wrong?


Link to sample : https://github.com/saneeshdo/SyncFusionTest



AD Aravind Dharani Syncfusion Team October 16, 2024 01:24 PM UTC

Hi Nithesh,

We have checked your GitHub repository and made the necessary changes to convert the DOCX file into SFDT and save the SFDT back to a DOCX file. Please find the modified sample from the attachment.


Regards,

Aravind D


Attachment: SyncFusionTest_56c28d38.zip


KN Kuntady Nithesh October 17, 2024 08:36 AM UTC

"The sfdtContent retrieved in the LoadSFDT() method appears quite different from the sfdtText obtained through the ExportSFDT() method. The content retrieved by LoadSFDT() seems encrypted. How can I retrieve the sfdtText in the same format that was originally used to create the sample.docx in the ExportSFDT() method?"



AD Aravind Dharani Syncfusion Team October 21, 2024 09:47 AM UTC

Hi Nithesh,

You can retrieve the SFDT text without encryption. Please refer to the documentation below for instructions on how to optimize and unoptimize the SFDT text. We have also modified the sample for your reference. Please find it attached.

 

Documentation link: Optimize the SFDT file in Angular Document editor component | Syncfusion


Regards,

Aravind D


Attachment: SyncFusionTest_ef4f3c0f.zip

Loader.
Up arrow icon