Compare does not strike through the revised data

I am trying to compare two documents using the .Compare function. The issue is when change is made inside a textbox, the strikethrough is not working.

Aspose.Words.Comparing.CompareOptions compareOptions = new Aspose.Words.Comparing.CompareOptions
{
    IgnoreFormatting = true,
    IgnoreCaseChanges = false,
    IgnoreTables = false,
    IgnoreFields = false,
    IgnoreFootnotes = false,
    IgnoreComments = false,
    IgnoreTextboxes = false,
    IgnoreHeadersAndFooters = false,
    Granularity = Granularity.CharLevel,
    CompareMoves = true
};

document1.Compare(document2, "Comparison", DateTime.Now, compareOptions);

These are the options I am using.
Expected (From Word):

Actual:

@yojat Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

1st.docx (16.5 KB)

2nd.docx (16.4 KB)

Please find them here

@yojat Thank you for additional information. As I can see Aspose.Words comparison result looks the same as MS Word comparison result.
Aspose.Words: out.docx (10.6 KB)
MS Word: ms.docx (18.8 KB)

@alexey.noskov Thank you!
Is the code used to generate the above document the same as the one I previously provided? If not, can you please share it?

@yojat Yes, the code is the same. Also I tried comparing with default compare options with the same result. I used the latest 24.9 version of Aspose.Words.

@alexey.noskov
I see. I suspect that there’s an issue in the way I am saving the document.

HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
opt.PrettyFormat = true;
opt.ExportEmbeddedCss = true;
opt.ExportEmbeddedFonts = true;
opt.ExportEmbeddedImages = true;
opt.ExportEmbeddedSvg = true;
opt.ShowPageBorder = false;
opt.SaveFormat = SaveFormat.Docx;
// ...
document1.Save(memoryStream, opt);

These are my options. The textboxes in the generated document is an image (I’ve attached the generated compared file). Are there any options that will export the textbox as a textbox?
2nd (3).docx (10.1 KB)

@yojat You cannot use SaveFormat.Docx in HtmlFixedSaveOptions. If save the document as HtmlFixed the output looks the same as the document looks in MS Word:
out.zip (13.8 KB)

I removed this, but the problem still exists.

@alexey.noskov
So I found out, there’s a separate function that creates the document before sending it to compare function.

public async Task<string> GetDocInHTMLFormat(string documentPath)
{
    string filePath = Path.Combine(_rootPath, documentPath);
    Document doc = new Document(templatePath);
    HtmlSaveOptions opt = new HtmlSaveOptions(SaveFormat.Html);
    opt.ExportImagesAsBase64 = true;
    using (MemoryStream ms = new MemoryStream())
    {
        doc.Save(ms, opt);
        ms.Position = 0;
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(ms);
        return await Task.FromResult<string>(xmlDoc.InnerXml);
    }
}

This function creates the image of the textbox.
Like so,

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Style-Type" content="text/css" /><meta name="generator" content="Aspose.Words for .NET 24.9.0" /><title></title></head><body style="line-height:108%; font-family:Calibri; font-size:11pt"><div><p style="margin-top:0pt; margin-bottom:8pt"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAAqCAYAAACa0kYSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOxAAADsQBlSsOGwAAA2FJREFUeJzt3c1K60AYBuB3DucW4s/abbFk41pQ3EzoXix4BwHB3oOQgpg7ECLuS7JrwbW7mG5ddWVyEXMWnoQk5rdUe07nfUCs05kvX6EvCdOoAoACEe0qAQC/AUApZp1o1wghsse/ttgHEf0QBp1IAww6kQYYdCINMOhEGmDQiTTAoBNpYGNBtywLi8ViU+WIaIM6B92yLAghKr+Wy2XreiEEnp6eOjfWd/4umU6nmE6n/2w9+v/87jrR9/3ssRACURRhMBh0PlDfu+94tx7RZqm+AKgoigpjUko1n88VPu+dV+W66fNKKeV5Xu28qvl919TNy487jlOobdt29nNao+01V9XN9yylrOylqU/btmv7rBtftx7tNpR+j2WtAlVBL7/Bqt6McRwrACqO48Zj5IPeZ01dD1JK5XleZf0oigrrHMdRUsrsNZafLx+zXDf9nn/9ac22PtO55UA29b9OPdp9+aBvdNd9Pp9nj0ejEVarVe3ct7e33vW7rKnqYblcIggCXF1dZc9dXl5iNpsBAAaDAaSU2V7Dy8sLbm5uEIYhACAMQziO8+VYVXV938/Gb29vs/Hr62sEQYAkSWr7rNPWf996pJ9v/Xjt/f39y5hhGIjjGOfn55033NZZU9VDfgNxPB4X5p2eniIMQyRJgqOjIxwfH+P5+RkA8Pr6CtM0K+tLKTuNG4YBAPj4+Gjts05T/+vUI3103ozbJMMwoJRCkiTY29vDcDhs3dhbZ02ZatjgM00T9/f3ODg4wMnJSRbMJEngui4eHh4q1wVB0Gk8PZPv7+/36jmvqX+iJlu9YSYN03evSS/Nm64Ezs7OEAQBZrMZhsMhgM+z/OPjI2zbrq0LoFDXsqzsePmPtNI6Xfo/PDwsXHp36b9PPdLPjwd9sVgULkE9z2s9M6+zpsz3fYzH40KdcnBs24brullt0zQxmUwwGo1q68ZxXKh7d3eXHW8ymWTjq9Wq9qqg7OLiAq7rFnrs0n+feqQXgc/d2m33QUQb9vcvzAiA97oTaYFBJ9IAg06kAQadSAMMOpEGGHQiDTDoRBpg0Ik0wKATaYBBJ9IAg06kAQadSAMMOpEGGHQiDTDoRBpg0Ik0wKATaYBBJ9IAg06kAQadSAMCpf/PREQ7RWy7ASL6IX8ATQ7OGZiByAEAAAAASUVORK5CYII=" width="250" height="42" alt="" style="margin:3.6pt 9pt; -aw-left-pos:0pt; -aw-rel-hpos:column; -aw-rel-vpos:paragraph; -aw-top-pos:14.4pt; -aw-wrap-type:square; float:left; position:relative" /></p></div></body></html>

Is there anything I can set here to stop the conversion?

@yojat In the above provided code you are saving to flow HTML. You should note that MS Word documents and HTML documents object models are quite different. This makes it not always possible to provide 100% fidelity after conversion one format to another.

1 Like