How to optimize the SFDT file 11 Jun 2024 4 minutes to read
Starting from version v21.1.x, the SFDT file generated in Word Processor 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 and provides the following benefits,
File transfer between client and server through the internet gets faster.
The new optimized SFDT files require less storage space than the old SFDT files.
Hence, the optimized SFDT file can’t be directly manipulated as JSON string.
This feature comes with a public API to switch between the old and new optimized SFDT format, allowing backward compatibility.
As a backward compatibility to create older format SFDT files, refer the following code changes,
Expand Table
Client/Server
Old Code
New Code from v21.1.x
Client-side
< template >
< ejs-documenteditorcontainer ></ ejs-documenteditorcontainer >
</ template >
< template >
< ejs-documenteditorcontainer : documentEditorSettings = "settings" ></ ejs-documenteditorcontainer >
</ template >
< script setup >
import { DocumentEditorContainerComponent as EjsDocumenteditorcontainer } from '@syncfusion/ej2-vue-documenteditor' ;
const settings = { optimizeSfdt : false };
</ script >
< template >
< ejs-documenteditorcontainer : documentEditorSettings = "settings" ></ ejs-documenteditorcontainer >
</ template >
< script >
import { DocumentEditorContainerComponent } from '@syncfusion/ej2-vue-documenteditor' ;
export default {
name : "App" ,
components : {
"ejs-documenteditorcontainer" : DocumentEditorContainerComponent
},
data : function () {
return {
settings : { optimizeSfdt : false }
};
},
};
</ script >
Server-side C#
WordDocument sfdtDocument = WordDocument . Load ( stream , formatType );
string sfdt = Newtonsoft . Json . JsonConvert . SerializeObject ( sfdtDocument );
WordDocument sfdtDocument = WordDocument . Load ( stream , formatType );
sfdtDocument . OptimizeSfdt = false ;
string sfdt = Newtonsoft . Json . JsonConvert . SerializeObject ( sfdtDocument );
Server-side Java
String sfdtDocument = WordProcessorHelper . load ( stream , formatType );
String sfdtDocument = WordProcessorHelper . load ( stream , formatType , false );
To convert from older format SFDT from a new optimized SFDT file, refer the following code example,
Expand Table
Client/Server
Code example
Client-side
< template >
< ejs-documenteditorcontainer : documentEditorSettings = "settings" ></ ejs-documenteditorcontainer >
</ template >
< script setup >
import { DocumentEditorContainerComponent as EjsDocumenteditorcontainer } from '@syncfusion/ej2-vue-documenteditor' ;
const settings = { optimizeSfdt : false };
</ script >
< template >
< ejs-documenteditorcontainer : documentEditorSettings = "settings" ></ ejs-documenteditorcontainer >
</ template >
< script >
import { DocumentEditorContainerComponent } from '@syncfusion/ej2-vue-documenteditor' ;
export default {
name : "App" ,
components : {
"ejs-documenteditorcontainer" : DocumentEditorContainerComponent
},
data : function () {
return {
settings : { optimizeSfdt : false }
};
},
};
</ script >
Server-side C#
using ( Syncfusion . DocIO . DLS . WordDocument docIODocument = WordDocument . Save ( optimizedSfdt )) {
sfdtDocument = WordDocument . Load ( docIODocument );
sfdtDocument . OptimizeSfdt = false ;
string oldSfdt = JsonSerializer . Serialize ( sfdtDocument );
}
Server-side Java
WordDocument docIODocument = WordProcessorHelper . save ( optimizedSfdt );
String oldSfdt = WordProcessorHelper . load ( docIODocument , false );