@@ -99,7 +99,7 @@ public string SpellCheck([FromBody] SpellCheckJsonData spellChecker)
9999 return "{\" SpellCollection\" :[],\" HasSpellingError\" :false,\" Suggestions\" :null}" ;
100100 }
101101 }
102- // GET api/values
102+ // GET api/values
103103 [ HttpGet ]
104104 public IEnumerable < string > Get ( )
105105 {
@@ -144,7 +144,7 @@ public class CustomParameter
144144 [ HttpPost ]
145145 [ EnableCors ( "AllowAllOrigins" ) ]
146146 [ Route ( "SystemClipboard" ) ]
147- public string SystemClipboard ( [ FromBody ] CustomParameter param )
147+ public string SystemClipboard ( [ FromBody ] CustomParameter param )
148148 {
149149 if ( param . content != null && param . content != "" )
150150 {
@@ -181,7 +181,7 @@ public class UploadDocument
181181 [ HttpPost ]
182182 [ EnableCors ( "AllowAllOrigins" ) ]
183183 [ Route ( "RestrictEditing" ) ]
184- public string [ ] RestrictEditing ( [ FromBody ] CustomRestrictParameter param )
184+ public string [ ] RestrictEditing ( [ FromBody ] CustomRestrictParameter param )
185185 {
186186 if ( param . passwordBase64 == "" && param . passwordBase64 == null )
187187 return null ;
@@ -208,7 +208,7 @@ public string LoadDefault()
208208 [ Route ( "LoadDocument" ) ]
209209 public string LoadDocument ( [ FromForm ] UploadDocument uploadDocument )
210210 {
211- string documentPath = Path . Combine ( path , uploadDocument . DocumentName ) ;
211+ string documentPath = Path . Combine ( path , uploadDocument . DocumentName ) ;
212212 Stream stream = null ;
213213 if ( System . IO . File . Exists ( documentPath ) )
214214 {
@@ -355,6 +355,46 @@ public FileStreamResult Export(IFormCollection data)
355355 FileDownloadName = fileName
356356 } ;
357357 }
358+ [ HttpPost ]
359+ [ Route ( "CompareDocuments" ) ]
360+ public string CompareDocuments ( IFormCollection data )
361+ {
362+ if ( data . Files . Count < 2 ) return null ;
363+ IFormFile originalDoc = data . Files [ 0 ] ;
364+ IFormFile revisedDoc = data . Files [ 1 ] ;
365+ string type1 = Path . GetExtension ( originalDoc . FileName ) ? . ToLower ( ) ?? ".docx" ;
366+ string type2 = Path . GetExtension ( revisedDoc . FileName ) ? . ToLower ( ) ?? ".docx" ;
367+
368+ Stream originalStream = GetDocumentStream ( originalDoc , type1 ) ;
369+
370+ Stream revisedStream = GetDocumentStream ( revisedDoc , type2 ) ;
371+
372+ using ( originalStream )
373+ using ( WDocument originalDocument = new WDocument ( originalStream , WFormatType . Docx ) )
374+ using ( revisedStream )
375+ using ( WDocument revisedDocument = new WDocument ( revisedStream , WFormatType . Docx ) )
376+ {
377+ originalDocument . Compare ( revisedDocument ) ;
378+ var wordDoc = Syncfusion . EJ2 . DocumentEditor . WordDocument . Load ( originalDocument ) ;
379+ return Newtonsoft . Json . JsonConvert . SerializeObject ( wordDoc ) ;
380+ }
381+ }
382+ private Stream GetDocumentStream ( IFormFile file , string fileType )
383+ {
384+ if ( fileType == ".docx" )
385+ {
386+ return file . OpenReadStream ( ) ;
387+ }
388+
389+ using ( var reader = new StreamReader ( file . OpenReadStream ( ) ) )
390+ {
391+ string sfdtContent = reader . ReadToEnd ( ) ;
392+ WDocument document = WordDocument . Save ( sfdtContent ) ;
393+ var stream = new MemoryStream ( ) ;
394+ document . Save ( stream , Syncfusion . DocIO . FormatType . Docx ) ;
395+ return stream ;
396+ }
397+ }
358398 private string GetValue ( IFormCollection data , string key )
359399 {
360400 if ( data . ContainsKey ( key ) )
0 commit comments