Hi, i’m doing a word compare with the following documents AsposeTest4.7z (33.2 KB)
This is the code of the test:
public class AsposeTest4 {
public static void main(String[] args) throws Exception {
Document doc1 = new Document("C:\\AsposeTest\\" + "LEFT.docx");
Document doc2 = new Document("C:\\AsposeTest\\" + "RIGHT.docx");
removeSdt(doc1);
removeSdt(doc2);
//COMMENT THESE SAVES FOR A DIFFERENT RESULT
doc1.save("C:\\AsposeTest\\" + "COMPARE RESULT LR.docx", SaveFormat.DOCX);
doc2.save("C:\\AsposeTest\\" + "COMPARE RESULT LR2.docx", SaveFormat.DOCX);
doc1.compare(doc2, "Me", new Date());
RevisionCollection revisions = doc1.getRevisions();
for (int i = 0; i < revisions.getCount(); i++) {
Revision r = revisions.get(i);
Node node = r.getParentNode();
String temp = node.getText();
System.out.println(temp);
}
}
@SuppressWarnings("unchecked")
private static void removeSdt(Document doc) {
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>)doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
try {
if (sdt.getXmlMapping().isMapped()) {
sdt.getXmlMapping().delete();
}
sdt.removeSelfOnly(); // Removes just this SDT node itself, but keeps the content of it inside the document tree
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
If i do the compare without documents save i get this result:
22-Sep-15
September 15, 2022
22-Nov-13 11:59 PM
,000.
.000,
First version of this document was created by a german user
I changed some UDF values and the end date to 20th and its format to ‘MMMM d,
yyyy
h:mm am/pm’
added this
deleted the previous part
,500.
.500,
.66
,69
.
,
MonetaryLC1aNumTestadate field123aa
MonetaryLC1a
MonetaryLC1
NumTesta
NumTest
date field123a
date field123
MonetaryLC1aNumTestadate field123aa
MonetaryLC1a
MonetaryLC1
NumTesta
NumTest
date field123a
date field123
,700.20
.700,30
.600
,800
9/
/
.09.
,800.
.800,
.
,
9/
/
.09.
WITH document save i get this result:
22-Sep-15
September 15, 2022
22-Nov-13 11:59 PM
,000.
.000,
First version of this document was created by a german user
I changed some UDF values and the end date to 20th and its format to ‘MMMM d,
yyyy
h:mm am/pm’
added this
deleted the previous part
,500.
.500,
.66
,69
.
,
,700.20
.700,30
.600
,800
9/
/
.09.
,800.
.800,
.
,
9/
/
.09.
The biggest differences are the table headers, are considered revisions without save but not with save.
I’m doing the compare on memory so saving the document in the middle is not a real option for me. What does document.save() do that i could do to get the result without actually performing the save.
Thank you.