Hello,
I tried comparing two docx documents using Aspose library in .NET and they worked by producing an output document which contained revisions after comparing input docx 1 and 2 but the same thing does not work in Java. It generates a docx but the content is empty.
Source code:
public int compareDocuments(String expectedFile, String actualFile, Map<String, String> testData) throws Exception {
Document expectedDoc = new Document(expectedFile);
Document actualDoc = new Document(actualFile);
int compResult = 0;
String comparedfileName = expectedFile;
String comparedDocPath =System.getProperty("user.dir")+"\\ComparedDocs";
String []fileNames = comparedfileName.split("\\\\");
System.out.println("Compared File Name: "+fileNames[9]);
try{
CompareOptions options = new CompareOptions();
options.setIgnoreFormatting(Boolean.valueOf(testData.get("Format")));
options.setIgnoreHeadersAndFooters(Boolean.valueOf(testData.get("Header")));
options.setIgnoreCaseChanges(Boolean.valueOf(testData.get("Case")));
options.setIgnoreTables(Boolean.valueOf(testData.get("Tables")));
options.setIgnoreFields(Boolean.valueOf(testData.get("Fields")));
options.setIgnoreComments(Boolean.valueOf(testData.get("Comments")));
options.setIgnoreTextboxes(Boolean.valueOf(testData.get("Textbox")));
options.setIgnoreFootnotes(Boolean.valueOf(testData.get("Footnotes")));
options.setTarget(ComparisonTargetType.NEW);
// Compare documents
expectedDoc.compare(actualDoc, "author", new Date(), options);
//Save Compared document
//expectedDoc.save(comparedDocPath+"\\"+fileNames[9],SaveFormat.DOCX );
actualDoc.save(comparedDocPath+"\\"+fileNames[9]);
// Actual Revision count should be less then and equal to Expected Revision count
if(expectedDoc.getRevisions().getCount() <= Integer.valueOf(testData.get("ExpectedRev"))){
compResult = Integer.valueOf(testData.get("ExpectedRev"));
}
else {
compResult = expectedDoc.getRevisions().getCount();
}
}
catch(Exception e){
}
// return the revision count
return compResult;
}
Input Doc 1: TC-4426.docx (443.5 KB)
Input Doc 2TC-4426.docx (170.2 KB)
Output Doc: TC-4426.docx (16.0 KB)