Comparing .doc with .docx

Hi,

Sometimes when I compare .doc with .docx documents I get the following exception, do you have any ideas as to what can be causing this error?

I tried using aspose-words-16.2.0-jdk16.jar and aspose-words-16.3.0-jdk16.jar files but I get the same error

java.lang.IllegalStateException
at com.aspose.words.zzZWU.endElement(Unknown Source)
at com.aspose.words.zz0E.zzZYD(Unknown Source)
at com.aspose.words.zz0E.zzZYG(Unknown Source)
at com.aspose.words.zz0E.zzZYQ(Unknown Source)
at com.aspose.words.zzZW7.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)

Here is my code:

Document doc1 = new Document(file1Path);
doc1.save(diffFilePath + ".htm", SaveFormat.HTML);
Document doc2 = new Document(file2Path);
doc2.save(diffFilePath + ".htm", SaveFormat.HTML);
if (doc1.hasRevisions())
{
    doc1.acceptAllRevisions();
}
if (doc2.hasRevisions())
{
    doc2.acceptAllRevisions();
}
doc2.compare(doc1, "user", new java.util.Date()); // doc1 now contains changes as revisions.
doc2.save(diffFilePath + "temp_diff.html", SaveFormat.HTML);

Any help will be greatly appreciated

Hi Moises,

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

This issue keeps happening even after we got the latest version of the jar files, here are a couple documents that give this error when we compare them.

Document doc1 = new Document(file1Path + file1Name);
doc1.save(diffFilePath + File.separator + Utilities.getFilePrefix(file1Name) + ".htm", SaveFormat.HTML);
Document doc2 = new Document(file2Path + file2Name);
doc2.save(diffFilePath + File.separator + Utilities.getFilePrefix(file2Name) + ".htm", SaveFormat.HTML);
if (doc1.hasRevisions())
{
    doc1.acceptAllRevisions();
}
if (doc2.hasRevisions())
{
    doc2.acceptAllRevisions();
}
doc2.compare(doc1, "user", new java.util.Date()); // doc1 now contains changes as revisions.
doc2.save(diffFilePath + File.separator + "temp_diff.html", SaveFormat.HTML);

in this case doc1 is Consent_1792.rtf, doc2 is Consent_1791.rtf

the exception in line :

doc2.save(diffFilePath + File.separator + "temp_diff.html", SaveFormat.HTML);

Hi Moises,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for Java 16.7.0 and have not found the shared issue. Please use Aspose.Words for Java 16.7.0.

Hi Tahir,

After get latest version Aspose.Words for Java 16.8.0 we have not found above issue anymore.

But now when we compare 2 document with header, the header removed not display as red color.
But it do display as green color when we revert to add header when compare.

Compare code is the same with Moises post above.

File compare is attached to this post.

Thank you,

Dat Luu

Hi Dat Luu,

Thanks for your inquiry.

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.

Hi Tahir,

Please take a look at these screenshot.

Thank you,

Dat Luu

Hi Dat Luu,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same behavior as MS Word does. Its means that if you compare “With Header document.docx” with “NoHeader document.docx” or “NoHeader document.docx” with “With Header document.docx”, you will get the same output as generated by Aspose.Words.

Hi Tahir,

So what you mean is Aspose.Words only do highlight the header that added with Green color and do not highlight the header that removed with Red color?

Best,

Dat Luu

Hi Dat Luu,

Thanks for your inquiry. Aspose.Words mimics the same behavior as MS Word does.

The color information of track changes is not stored in Word document and cannot be controlled by Aspose.Words. Please change the colors of track changes options in MS Word and check the input and output documents. See the attached images for detail.

If you still face any issue, please share complete detail of your use case along with expected output document. We will then provide you more information about your query.

Hi Tahir,

Please check the screenshot for result compare by MS word. It still display remove is Strikethrough and red color in the removed header. Please do the compare with file With Header document.docx and NoHeader document.docx in Aspose.Word to get the result, it’s not display Strikethrough and red color in header like MS Word did.

You can check 2 screenshot i atached, one is result from MS Word, one is result from Aspose.Word

I am using the same query with Moises upper.

Best,

Dat Luu

Hi Dat Luu,

Thanks for your inquiry. Please open the document generated by Aspose.Words in MS Word and check the output. You will see the same output.

Could you please share how you are checking the output of Aspose.Words?

*mescobar:

Document doc1 = new Document(file1Path + file1Name);
doc1.save(diffFilePath + File.separator + Utilities.getFilePrefix(file1Name) + ".htm", SaveFormat.HTML);
Document doc2 = new Document(file2Path + file2Name);
doc2.save(diffFilePath + File.separator + Utilities.getFilePrefix(file2Name) + ".htm", SaveFormat.HTML);

if (doc1.hasRevisions())
{
    doc1.acceptAllRevisions();
}

if (doc2.hasRevisions())
{
    doc2.acceptAllRevisions();
}
doc2.compare(doc1, "user", new java.util.Date()); // doc1 now contains changes as revisions. 
doc2.save(diffFilePath + File.separator + "temp_diff.html", SaveFormat.HTML);

Hi Tahir,
We are using code output, and save format is HTML.
Thank you,
Dat Luu*

Hi Dat Luu,

Thanks for your inquiry. In your case, we suggest you please save the final document to HtmlFixed file format and change the color of revisions. The RevisionOptions class allows to control how document revisions are handled during layout process. You can use this class when document is exported to fixed page file formats e.g. Pdf, HtmlFixed, Png etc. Please check the following code example for your kind reference. Hope this helps you.

Document doc1 = new Document(MyDir + "With+Header+document.docx"); 
Document doc2 = new Document(MyDir + "NoHeader+document.docx");
doc2.compare(doc1, "user", new java.util.Date()); 
RevisionOptions options = doc2.getLayoutOptions().getRevisionOptions();
options.setInsertedTextColor(RevisionColor.YELLOW);
options.setDeletedTextColor(RevisionColor.BLUE);
options.setInsertedTextEffect(RevisionTextEffect.UNDERLINE);
options.setDeletedTextEffect(RevisionTextEffect.STRIKE_THROUGH);
doc2.save(MyDir + "Out v16.8.0.html", SaveFormat.HTML_FIXED);

Hi Tahir,

this is my code now:

Document doc1 = new Document(file1Path + file1Name);
doc1.save(diffFilePath + File.separator + Utilities.getFilePrefix(file1Name) + ".docx", SaveFormat.DOCX);
Document doc2 = new Document(file2Path + file2Name);
doc2.save(diffFilePath + File.separator + Utilities.getFilePrefix(file2Name) + ".docx", SaveFormat.DOCX);

if (doc1.hasRevisions())
{
    doc1.acceptAllRevisions();
}

if (doc2.hasRevisions())
{
    doc2.acceptAllRevisions();
}

doc2.compare(doc1, "user", new java.util.Date());
doc2.getLayoutOptions().getRevisionOptions().setInsertedTextColor(RevisionColor.BRIGHT_GREEN);
doc2.getLayoutOptions().getRevisionOptions().setDeletedTextColor(RevisionColor.RED);
doc2.getLayoutOptions().getRevisionOptions().setInsertedTextEffect(RevisionTextEffect.UNDERLINE);
doc2.getLayoutOptions().getRevisionOptions().setDeletedTextEffect(RevisionTextEffect.STRIKE_THROUGH);
doc2.save(diffFilePath + File.separator + diffFileName, SaveFormat.HTML_FIXED);

The result still has no effect, does it work well in your side?

Thank you,

Dat Luu

Hi Dat Luu,

Thanks for your inquiry. We have tested the scenario and have noticed that the text “Test for Ontime Tickets” is not in deleted revisions. This is the reason you are not getting the deleted text color and effect in output document. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14242. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@mescobar,

The issues you have found earlier (filed as WORDSNET-14242) have been fixed in this Aspose.Words for .NET 17.8 update and this Aspose.Words for Java 17.8 update.