We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Strange result of compare document with lists

Hello, I have problem with compare logic between document in case when I add lists to documents with different styles. After exporting result I do not see any differences (revision collection is empty).
Here is the example of code which generate results which I do not expect.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.getListFormat().applyNumberDefault();
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();

Document doc2 = new Document();
DocumentBuilder builder2 = new DocumentBuilder(doc2);

builder2.getListFormat().applyBulletDefault();
builder2.writeln("Item 1");
builder2.writeln("Item 2");
builder2.getListFormat().removeNumbers();

CompareOptions compareOptions = new CompareOptions();
compareOptions.setGranularity(Granularity.CHAR_LEVEL);
doc.compare(doc2, "test", Date.from(Instant.now()), compareOptions);
doc.save("compare.pdf");

Also when I generate 2 documents in that way word also cannot detect any change but I have no idea why because I see it

@PROCUREMENT2 Thank you for reporting the problem to us. I have managed to reproduce the mentioned behavior. But it looks like an expected behavior because MS Word also does not see any difference between the document with identical content and different list styles. For example, you can try comparing the attached documents (produced actually by your code) in MS Word and it will report no differences between the documents. doc1.docx (12.8 KB)
doc2.docx (8.0 KB)

@alexey.noskov
I see that aspose is consistent with Word, I think problem is how this lists are created so even word cannot handle that comparison. When I recreate identical word files with lists in word and perform compare, it is able to detect changes

@PROCUREMENT2 The problem occurs because in both document list id is the same. So if you compare document.xml you will notice they are the same. But if you for example create one list and then another in on of the documents, list id will be incremented and the change will be detected. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

List lst = doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT);

builder.getListFormat().applyNumberDefault();
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();

Document doc2 = new Document();
DocumentBuilder builder2 = new DocumentBuilder(doc2);

builder2.getListFormat().applyBulletDefault();
builder2.writeln("Item 1");
builder2.writeln("Item 2");
builder2.getListFormat().removeNumbers();

CompareOptions compareOptions = new CompareOptions();
compareOptions.setGranularity(Granularity.CHAR_LEVEL);
doc.compare(doc2, "test", Date.from(Instant.now()), compareOptions);
doc.save("C:\\Temp\\compare.docx");

@alexey.noskov
So there is no possibility to have consistent method which generates based on the same code 2 documents which will be detected as change. I am asking because in my case I generate words based on some metadata and when it change I generate different type of list and based what you write in each case I will have the same listIds and this will cause that I will be not able to compare both of these lists

@PROCUREMENT2 It seems my first assumption regarding equivalent list ids was not fully right, because in MS Word generated document list ids are also the same, but the documents are compared properly.
I have logged this problem as WORDSNET-23724. We will further investigate the problem and let you know once it is resolved or we have additional information for you.