Using Aspose.Words for .Net I’m having an issue where images are being flagged as added/removed when run on a document generated on different versions of Aspose.
I’m in the process of upgrading to 24.1 but have hit an issue that I’ve tracked down to appearing between Aspose 22.9 and 22.10. If I run my program with my input on Aspose 22.9 I get the following output:
Image_22-9.DOCX (1.5 MB)
Then I upgrade to 22.10 (with no other changes) and run it again to get:
Image_22-10.DOCX (1.5 MB)
The files look the same, but running our compare code I get the following result:
Image_Compare.DOCX (1.5 MB)
From inspecting the xml content, I believe they are being flagged as different because the prior version resulted in <wp:inline distT="0" distB="0" distL="0" distR="0">
while the newer version results in <wp:inline>
. I was able to confirm this by manually editing the 22.10 document and rerunning the compare. With the attributes added, the diff came back clean.
I also tried to track down where in our process the distT="0" distB="0" distL="0" distR="0"
was getting added in 22.9. It seems to occur due to these lines of code:
HeaderFooter hf = builder.CurrentSection.HeadersFooters[extractType];
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
// PrettyFormat preserves field code tags
saveOptions.PrettyFormat = true;
// ExportImagesAsBase64 makes copying of images work
saveOptions.ExportImagesAsBase64 = true;
saveOptions.SaveFormat = SaveFormat.Html;
string content = hf.ToString(saveOptions);
I’m looking for a way to either get the attributes back on the tag in the new version or to exclude that specific difference from the compare. Changes to the old version of the document will not be possible for our use case as they will have been generated previously. Any help would be greatly appreciated.
Below is the code we are using to do the compare:
Document initialDoc = new Document(InputFileName);
Document compareDoc = new Document(CompareFileName);
CompareOptions compareOptions = new CompareOptions
{
IgnoreDmlUniqueId = true
};
WriteLogLine("Creating comparison document.");
initialDoc.Compare(compareDoc, "System", DateTime.Now, compareOptions);
Revision[] revs = initialDoc.Revisions.Cast<Revision>().ToArray<Revision>();
foreach (Revision rev in revs)
{
RevisionType type = rev.RevisionType;
switch (type)
{
case RevisionType.Insertion:
rev.Author = "Adder";
break;
case RevisionType.Deletion:
rev.Author = "Remover";
break;
case RevisionType.FormatChange:
rev.Author = "Styler";
break;
case RevisionType.StyleDefinitionChange:
rev.Accept();
break;
case RevisionType.Moving:
rev.Author = "Relocator";
break;
}
}
if (string.IsNullOrEmpty(OutputFileName))
{
if (initialDoc.Revisions.Count == 0)
{
OutputFileName = Path.Combine(Path.GetDirectoryName(InputFileName),
Path.GetFileNameWithoutExtension(InputFileName)) + "_NoDiff." + outputExt;
} else
{
OutputFileName = Path.Combine(Path.GetDirectoryName(InputFileName),
Path.GetFileNameWithoutExtension(InputFileName)) + "_Compare." + outputExt;
}
}
WriteLogLine("Saving comparison document to {0}.", OutputFileName);
initialDoc.Save(OutputFileName, outputFormat);