Free Support Forum - aspose.com

Document.Compare ignores the Move revisions using .NET

Hi,


I am testing Apsose Word compare functionality based on sample project “DocumentComparison.sln”.

I was wondering if there is a way to compare more than two documents with each other?
Do I need to create my own class to achive this or there is already something out there?

Thanks,
David

Some code from project:

“DocumentComparisonUtil.”
“docCompUtil.Compare(comparisonDocument1, comparisonDocument2, comparisonDocument, ref added, ref deleted);”

Hi David,


Thanks for your inquiry. The Document.Compare method compares two documents at a time. You need to call this method twice to compare three documents as shown below. Hope this helps you.

Please let us know if you have any more queries.

Document doc1 = new Document(MyDir + “doc1.docx”);<o:p></o:p>

Document doc2 = new Document(MyDir + "doc2.docx");

Document doc3 = new Document(MyDir + "doc3.docx");

doc1.Compare(doc2, "user", DateTime.Now);

doc1.Compare(doc3, "user", DateTime.Now);

doc1.Save(MyDir + @"Out v16.10.0.docx");

Hi Tahir,


I get error message : Compared documents must not have revisions.
Any idea?

I tried different documents and also sample documents from demo project DocumentComparison, but all generates same error.

Thanks,
David

p.s. is multiple compare also possible through DocumentComparison.DocumentComparisonUtil?

string document1 = dataDir + “Paris Trip1.docx”;
string document2 = dataDir + “Paris Trip2.docx”;
string document3 = dataDir + “Paris Trip3.docx”;

string[] documents = new string[] {document1,document2,document3 };

private static void CompareMultipleDocuments(string[] documents)
{
List list = new List();

for (int i = 0; i < documents.Count(); i++)
{
Document doc = new Document(documents[i]);
list.Add(doc);
}

Document doc1 = list[0];

string comparisonDocument = GetCompareDocumentName(list[0].ToString(), list[1].ToString());

doc1.Compare(list[0], “user”, DateTime.Now);
doc1.Compare(list[1], “user”, DateTime.Now);


doc1.Save(comparisonDocument);
}

Hi David,


Please accept my apologies for your inconvenience.

Please call Document.AcceptAllRevisions as shown below to fix the exception.
Stibbedevelopers:
p.s. is multiple compare also possible through DocumentComparison.DocumentComparisonUtil?
Yes, you can use the same approach in DocumentComparison.DocumentComparisonUtil.

Document doc1 = new Document(MyDir + “doc1.docx”);<o:p></o:p>

Document doc2 = new Document(MyDir + "doc2.docx");

Document doc3 = new Document(MyDir + "doc3.docx");

doc1.Compare(doc2, "user", DateTime.Now);

doc1.AcceptAllRevisions();

doc1.Compare(doc3, "user", DateTime.Now);

doc1.Save(MyDir + @"Out v16.10.0.docx");

Hi Tahir,


Thanks it works now!

Would you also show me how to compare more than two documents using DocumentComparisonUtil and save the result?

Could you send me some working samples?

Thanks,
David
Hi David,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. You can compare two document at a time. First you need to compare two document and then with third document. Please check following modified Compare method and let us know if you have any more queries.

public static void Compare(string document1, string document2, string document3, string comparisonDocument, int added,int deleted)

{

added = 0;

deleted = 0;

// Load both documents in Aspose.Words

Document doc1 = new Document(document1);

Document doc2 = new Document(document2);

Document doc3 = new Document(document3);

doc1.Compare(doc2, "a", DateTime.Now);

foreach (Revision revision in doc1.Revisions)

{

switch (revision.RevisionType)

{

case RevisionType.Insertion:

added++;

break;

case RevisionType.Deletion:

deleted++;

break;

}

Console.WriteLine(revision.RevisionType + ": " + revision.ParentNode);

}

doc1.AcceptAllRevisions();

doc1.Compare(doc3, "a", DateTime.Now);

foreach (Revision revision in doc1.Revisions)

{

switch (revision.RevisionType)

{

case RevisionType.Insertion:

added++;

break;

case RevisionType.Deletion:

deleted++;

break;

}

Console.WriteLine(revision.RevisionType + ": " + revision.ParentNode);

}

doc1.Save(comparisonDocument);

}


Hi Tahir,


Thank you! Just realised now! I got one more question for you.

Is it possible to use another color e.g. green instead of red for RevisionType of Moving?


Thanks,
David

p.s. it seems that aspsoe sees only deleted and inserted not what has been moved!?

Looks the problem is similar to the post below:

https://www.aspose.com/community/forums/thread/654288/getting-wrong-revisions-when-comparing-documents-when-some-pages-moved-in-docuemnt.aspxhttps://www.aspose.com/community/forums/thread/654288/getting-wrong-revisions-when-comparing-documents-when-some-pages-moved-in-docuemnt.aspx
Hi David,

Thanks for your inquiry. The latest version of Aspose.Words does support move revisions. You can check this revision by using RevisionType.Moving enumeration.

RevisionOptions class allows to control how document revisions are handled during layout process. Please check the members of this class. Please use following code snippet in GetDocumentData method. Hope this helps you.

Document doc = new Document(filePath);

doc.LayoutOptions.RevisionOptions.MovedFromTextColor = RevisionColor.Green;

Hi Tahir,


I tried your suggestion using Aspose Word 16.11.0 but no results. Please see my screen shot attachment.

Any idea? Did you test this on your side?

Thanks,
David
Hi David,

Thanks for your inquiry. Could you please attach your input Word documents along with DocumentComparison solution here for testing? We will investigate the issue on our side and provide you more information.

Hi Tahir,


It is just the same project from :
https://code.msdn.microsoft.com/office/Document-Comparison-by-b4c49161


As you sugested I added the doc.LayoutOptions.RevisionOptions.MovedFromTextColor = Aspose.Words.Layout.RevisionColor.Green; to GetDocumentData methode in Default.aspx.cs as you suggessted.

I cannot upload the same project because it is too big. I did attached two sapmle documents for testing. “TrackMoving.docx” and “TrackMoving2.docx”.

Regards,
David

p.s. Tahir: I just found out something strange. When I change the InsertedTextColor to Green like this:
doc.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Green; the inserted text in generated 0.png file is green but when I open it Microsoft Word it is Red! any idea? See attached 0.png file.



Hi David,

Thanks for sharing the documents. We have tested the scenario and have noticed that Document.Compare method ignores the "move" revisions in your case. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14445. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

There is no issue with LayoutOptions.RevisionOptions.MovedFromTextColor. If document contains the "move" revisions, Aspose.Words renders it correctly. Please note that LayoutOptions.RevisionOptions is only used for fixed page output document e.g. Pdf, Png, etc.
Stibbedevelopers:
doc.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Green; the inserted text in generated 0.png file is green but when I open it Microsoft Word it is Red! any idea? See attached 0.png file.
Please note that track changes information is MS Word (Application) level setting and does not store in the document. Therefore, it cannot be controlled by Aspose.Words. This is completely controlled by the viewer which opens the document.

A post was split to a new topic: RevisionOptions does not work