Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active July 21, 2022 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blog-aspose-cloud/da42ef95a0749c5db98a3dbdd95f2b25 to your computer and use it in GitHub Desktop.
Save blog-aspose-cloud/da42ef95a0749c5db98a3dbdd95f2b25 to your computer and use it in GitHub Desktop.
Compare Word Documents Online in Java

Compare Word Documents Online in Java


This Gist provides the details on how to compare Word Documents using Aspose.Words Cloud SDK for Java.
So in order to perform the comparison, first we will upload the input Word documents (original & modified) to cloud storage and then will compare text files using using compareDocument(...) method. Once compare text operation is completed, the resultant file is saved in cloud storage. For complete information, please visit Compare Word Documents Online in Java.

Compare Word Documents Online

Important Links

Product Page | Docs | Live Demo | Swagger UI | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

Compare Word Documents Online using Java Cloud SDK
For more examples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
// if baseUrl is null, WordsApi uses default https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
String firstDocument = "input-sample.docx";
String secondDocument = "input-sample-updated.docx";
String resultantFile = "Comparison.docx";
// read first Word document from local drive
File file = new File("c://Downloads/"+firstDocument);
// read second word document from local drive
File file2 = new File("c://Downloads/"+secondDocument);
// create file upload request
UploadFileRequest uploadRequest = new UploadFileRequest(Files.readAllBytes(file.toPath()), firstDocument, null);
// create 2nd file upload request
UploadFileRequest uploadRequest2 = new UploadFileRequest(Files.readAllBytes(file2.toPath()), secondDocument, null);
// upload file to cloud storage
wordsApi.uploadFile(uploadRequest);
// upload file to cloud storage
wordsApi.uploadFile(uploadRequest2);
// Create an instance of CompareData class
CompareData compareData = new CompareData();
// name to be used as author identifying the differences
compareData.setAuthor("Nayyer");
// specify the document to compare with
compareData.setComparingWithDocument(secondDocument);
compareData.setDateTime(OffsetDateTime.now());
// create Request instance by providing source, document to compare and resultant file name
CompareDocumentRequest request = new CompareDocumentRequest(firstDocument, compareData, null, null, null, null, null,resultantFile,null);
// initiate the document comparison
DocumentResponse result = wordsApi.compareDocument(request);
// print success message
System.out.println("Sucessfull completion of Compare Word Document !");
}catch(Exception ex)
{
System.out.println(ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment