Compare Output renders differently in wordpad and word

Hello Support
Please see attached original modified and compared output files.
In word line1 is properly shown as deleted however when same file is opened in wordpad i.e. rtf editor, It shows up differently

Please suggest.
CompareRTFOutput.zip (20.9 KB)

Code:


RtfSaveOptions rtfsvaeopt=new RtfSaveOptions();
rtfsvaeopt.ExportImagesForOldReaders=true;
rtfsvaeopt.MemoryOptimization=true;
rtfsvaeopt.UseAntiAliasing=true;
Document docOrg = new Document(“D:\Org.rtf”);
Document doc=new Document(“D:\Mod.rtf”)

Aspose.Words.CompareOptions options=new CompareOptions();
options.IgnoreFormatting=false;
options.IgnoreHeadersAndFooters=true;
docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons=false;
docOrg.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Blue;
docOrg.LayoutOptions.RevisionOptions.DeletedTextColor = Aspose.Words.Layout.RevisionColor.Red;
docOrg.Compare(doc,sAuthor,DateTime.Now,options);
docOrg.Save(“D:\Org-Mod-AsposeOutput.rtf”,rtfsvaeopt);

Thanks in advance.

@mandar_limaye

Thank you for your inquiry. We have investigated this scenario also based on your documents and sample code and found the output is expected Compare-RTF-Documents.zip (28.5 KB). We have also included the compared RTF document “Org-Mod-MSWordOutput.rtf” generated directly from MS Word and after opening in WordPad it is same as Aspose.Words API generated document.

For further investigation and exact solution we expect from you to share a compared document that shows the expected behavior while opening in WordPad. Thank you for your cooperation.

Hello Rizwan,
I have verified the things again on my side and yes indeed behavior is same from Aspose and Word.

The problem I am facing is that I want to show change for deleted in rtf format in some other component which supports only rtf and not doc or docx. So how I should go about for showing deleted content in rtf format itself.

Thanks in advance.

Regards
Mandar

@mandar_limaye

Thank you for writing back. You can iterate the Runs and check for IsDeletedRevision and change Font and Style accordingly. Please have a look at this sample code.

        //Load the documents
        Document docOrg = new Document(dataDir + @"Org.rtf");
        Document docMod = new Document(dataDir + @"Mod.rtf");

        Aspose.Words.CompareOptions options = new CompareOptions();
        options.IgnoreFormatting = false;
        options.IgnoreHeadersAndFooters = true;

        docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons = true;
        docOrg.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Blue;
        docOrg.LayoutOptions.RevisionOptions.DeletedTextColor = Aspose.Words.Layout.RevisionColor.Green;
        docOrg.LayoutOptions.RevisionOptions.DeletedTextEffect = Layout.RevisionTextEffect.StrikeThrough;
        docOrg.LayoutOptions.RevisionOptions.InsertedTextEffect = Layout.RevisionTextEffect.Italic;

        docOrg.Compare(docMod, "mandar_limaye", DateTime.Now, options);

        foreach (Run run in docOrg.GetChildNodes(NodeType.Run, true))
        {

            // Check if revision type is Deleted
            if (run.IsDeleteRevision)
            {
                run.Font.Color = Color.Red;
                run.Font.StrikeThrough = true;
            }
        }

        RtfSaveOptions rtfsvaeopt = new RtfSaveOptions();
        rtfsvaeopt.ExportImagesForOldReaders = true;
        rtfsvaeopt.MemoryOptimization = true;
        rtfsvaeopt.UseAntiAliasing = true;
        rtfsvaeopt.SaveFormat = SaveFormat.Rtf;

        docOrg.Save(dataDir + @"Org-Mod-AsposeOutput.rtf", rtfsvaeopt);

Hello RIzwan,

This works and I also worked on inserted revisions. Now last piece is if the cell is empty then this does not works as it doe not have any text. Hence I want to to check if run is of type cell then set its background as blue. Also if its an image or ole then also I want to underline it by blue line.

Thanks in advance.

Regards
Mandar

@mandar_limaye

Thank you for writing back.

Yes you can traverse all document Nodes and check the NodeType

        foreach (Node nod in docOrg.GetChildNodes(NodeType.Any, true))
        {
            if (nod.NodeType == NodeType.Paragraph)
            }
        } 

Please have a look at this sample code.

    Document docOrg = new Document(dataDir + @"Org.rtf");

    Document docMod = new Document(dataDir + @"Mod.rtf");

    Aspose.Words.CompareOptions options = new CompareOptions();
    options.IgnoreFormatting = false;
    options.IgnoreHeadersAndFooters = true;
    docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons = true;
    docOrg.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Blue;
    docOrg.LayoutOptions.RevisionOptions.DeletedTextColor = Aspose.Words.Layout.RevisionColor.Green;
    docOrg.LayoutOptions.RevisionOptions.DeletedTextEffect = Layout.RevisionTextEffect.StrikeThrough;
    docOrg.LayoutOptions.RevisionOptions.InsertedTextEffect = Layout.RevisionTextEffect.Italic;

    docOrg.Compare(docMod, "mandar_limaye", DateTime.Now, options);

    foreach (Node nod in docOrg.GetChildNodes(NodeType.Any, true))
    {
        if (nod.NodeType == NodeType.Paragraph)
        {
            Paragraph paraNode = (Paragraph)nod;

            foreach (Run run in paraNode.GetChildNodes(NodeType.Run, true))
            {
                if (run.IsDeleteRevision)
                {
                    run.Font.Color = Color.Red;
                    run.Font.StrikeThrough = true;
                }

                if (run.IsInsertRevision)
                {
                    run.Font.Color = Color.Blue;
                }
            }
        }

        if (nod.NodeType == NodeType.Cell)
        {
            Cell cellNode = (Cell)nod;

            foreach (Run run in cellNode.GetChildNodes(NodeType.Run, true))
            {
                if (run.IsDeleteRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Red;
                }

                if (run.IsInsertRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Blue;
                }
            }

            if (nod.NodeType == NodeType.Shape)
            {
                Shape shapeNode = (Shape)nod;

                if (shapeNode.IsDeleteRevision)
                {
                    shapeNode.Font.Underline = Underline.Single;
                    shapeNode.Font.UnderlineColor = Color.Red;
                }

                if (shapeNode.IsInsertRevision)
                {
                    shapeNode.Font.Underline = Underline.Single;
                    shapeNode.Font.UnderlineColor = Color.Blue;
                }
            }
        }
    }

    RtfSaveOptions rtfsvaeopt = new RtfSaveOptions();
    rtfsvaeopt.ExportImagesForOldReaders = true;
    rtfsvaeopt.MemoryOptimization = true;
    rtfsvaeopt.UseAntiAliasing = true;
    rtfsvaeopt.SaveFormat = SaveFormat.Rtf;

    docOrg.Save(dataDir + @"Org-Mod-AsposeOutput.rtf", rtfsvaeopt);

Hello Muhammad Rizwan,

Thanks for this code using anytype is quite helpful.

I tried this code and added one more condition for formatchange. I am facing some problems/Issues.

  1. When I am opening file using WordPad empty Cells are still not marked with blue background. Please note that in word then are shown with blue background with or without code related to cells. When I debug I found that if there is no content in cell there are no runs and so code does not run on such empty cells. I am not finding how to execute code for empty cells.

  2. When I am opening file in Word Shape and Ole objects are showing strike out as well as underline, However in WordPad no underline or strike out is visible. When I edit in WordPad then it is possible to underline and strike out shapes as well as OLE.

  3. For format change code is executing but change is not visible either in Word or in WordPad.

Thanks in advance.

Attaching files for org and mod files. Org.zip (1.8 MB)
Mod.zip (1.6 MB)
Also attaching images for compare output in word and wordpad Compare.zip (164.2 KB)

Code:


		string sAuthor="";
		RtfSaveOptions rtfsvaeopt=new RtfSaveOptions();
		
		rtfsvaeopt.ExportImagesForOldReaders=true; 
		rtfsvaeopt.MemoryOptimization=true;
		rtfsvaeopt.UseAntiAliasing=true;
		rtfsvaeopt.SaveFormat = SaveFormat.Rtf;
		
		Document docOrg = new Document("D:\\GroupDocs-Compare\\Compare\\Org.rtf");//("D:\\Aspose\\ModifiedOne.docx");
		Document doc=new Document("D:\\GroupDocs-Compare\\Compare\\Mod.rtf"); //("D:\\Aspose\\One.docx");
		sAuthor = doc.BuiltInDocumentProperties["Author"].Value.ToString();
		if (sAuthor.Equals("",StringComparison.InvariantCultureIgnoreCase)==true)
		{
			doc.BuiltInDocumentProperties.Author="System";
			docOrg.BuiltInDocumentProperties.Author="System";
			sAuthor = doc.BuiltInDocumentProperties["Author"].Value.ToString();				
		}
		Aspose.Words.CompareOptions options=new CompareOptions();
		options.IgnoreFormatting=false;
		options.IgnoreHeadersAndFooters=true;
		docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons=false;
		docOrg.LayoutOptions.RevisionOptions.ShowOriginalRevision=true; 
		docOrg.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Blue;
			docOrg.LayoutOptions.RevisionOptions.DeletedTextColor = Aspose.Words.Layout.RevisionColor.Red;
		docOrg.Compare(doc,sAuthor,DateTime.Now,options);
		
		foreach (Node nod in docOrg.GetChildNodes(NodeType.Any, true))
		{
			if (nod.NodeType == NodeType.Paragraph)
			{
				Paragraph paraNode = (Paragraph)nod;

				foreach (Run run in paraNode.GetChildNodes(NodeType.Run, true))
				{
					if (run.IsDeleteRevision)
					{
						run.Font.Color = Color.Red;
						run.Font.StrikeThrough = true;
					}
					if (run.IsInsertRevision)
					{
						run.Font.Color = Color.Blue;
                		run.Font.UnderlineColor=Color.Blue;     
            			run.Font.Underline=Underline.Single;
					}
					if (run.IsFormatRevision)
					{
                		run.Font.UnderlineColor=Color.Green;     
            			run.Font.Underline=Underline.Single;
					}
				}
			}

			if (nod.NodeType == NodeType.Cell)
			{
				Cell cellNode = (Cell)nod;

				foreach (Run run in cellNode.GetChildNodes(NodeType.Run, true))
				{
					if (run.IsDeleteRevision)
					{
						if (String.IsNullOrEmpty(run.Text))
						{
							cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Red;
						}
					}

					if (run.IsInsertRevision)
					{
						if (String.IsNullOrEmpty(run.Text))
						{
							cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Blue;
						}
					}
					
					if (run.IsFormatRevision)
					{
						run.Font.UnderlineColor=Color.Green;
            			run.Font.Underline=Underline.Single;
					}

				}

				if (nod.NodeType == NodeType.Shape)
				{
					Shape shapeNode = (Shape)nod;

					if (shapeNode.IsDeleteRevision)
					{
						shapeNode.Filled=true;
						shapeNode.FillColor=Color.Red;    							
						shapeNode.Font.Color = Color.Red;
						shapeNode.Font.StrikeThrough=true;  
					}
					if (shapeNode.IsInsertRevision)
					{
						shapeNode.Font.Underline = Underline.Single;
						shapeNode.Font.UnderlineColor = Color.Blue;
					}
				}
			}
		}
		
		
		
		
		docOrg.Save("D:\\GroupDocs-Compare\\Compare\\Org-Mod-AsposeOutput.rtf",rtfsvaeopt);
	}

@mandar_limaye

Thank you for writing back.

For empty cells that does not have Runs you can also check by first paragraph like:

            if (nod.NodeType == NodeType.Cell)
            {
                Cell cellNode = (Cell)nod;

                if (cellNode.FirstParagraph.IsDeleteRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Red;
                }

                if (cellNode.FirstParagraph.IsInsertRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Blue;
                }
             }

We have investigated this scenario and found even DOCX file having Shapes with formatting as Underline and Strikeout and convert to RTF from MS Word and open converted document in WordPad does not show the formatting as it’s limitation of WordPad to display formatting for different objects.

Please note MS Word display format changes and while opening in WordPad Format changes bubble information will not be display. However as you want to display Format change with Green underline then you have to first remove existing Format for such revision and then apply new font formatting as required.

                    if (run.IsFormatRevision)
                    {
                        run.Font.ClearFormatting();
                        run.Font.Color = Color.Green;
                        run.Font.UnderlineColor = Color.Green;
                        run.Font.Underline = Underline.Single;
                    }

Please have a look at this your updated sample code.

        // The path to the documents directory.
        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

        string sAuthor = "";

        Document docOrg = new Document(dataDir + "Org.rtf");
        Document doc = new Document(dataDir + "Mod.rtf");

        sAuthor = doc.BuiltInDocumentProperties["Author"].Value.ToString();

        if (sAuthor.Equals("", StringComparison.InvariantCultureIgnoreCase) == true)
        {
            doc.BuiltInDocumentProperties.Author = "System";
            docOrg.BuiltInDocumentProperties.Author = "System";
            sAuthor = doc.BuiltInDocumentProperties["Author"].Value.ToString();
        }

        Aspose.Words.CompareOptions options = new CompareOptions();
        options.IgnoreFormatting = false;
        options.IgnoreHeadersAndFooters = true;

        docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons = false;
        docOrg.LayoutOptions.RevisionOptions.ShowOriginalRevision = true;
        docOrg.LayoutOptions.RevisionOptions.RevisedPropertiesColor = Layout.RevisionColor.Green;
        docOrg.LayoutOptions.RevisionOptions.RevisedPropertiesEffect = Layout.RevisionTextEffect.Underline;
        docOrg.LayoutOptions.RevisionOptions.InsertedTextColor = Aspose.Words.Layout.RevisionColor.Blue;
        docOrg.LayoutOptions.RevisionOptions.InsertedTextEffect = Aspose.Words.Layout.RevisionTextEffect.Underline;
        docOrg.LayoutOptions.RevisionOptions.DeletedTextColor = Aspose.Words.Layout.RevisionColor.Red;
        docOrg.LayoutOptions.RevisionOptions.DeletedTextEffect = Aspose.Words.Layout.RevisionTextEffect.StrikeThrough;

        docOrg.Compare(doc, sAuthor, DateTime.Now, options);

        foreach (Node nod in docOrg.GetChildNodes(NodeType.Any, true))
        {
            if (nod.NodeType == NodeType.Paragraph)
            {
                Paragraph paraNode = (Paragraph)nod;

                foreach (Run run in paraNode.GetChildNodes(NodeType.Run, true))
                {
                    if (run.IsDeleteRevision)
                    {
                        run.Font.Color = Color.Red;
                        run.Font.StrikeThrough = true;
                    }

                    if (run.IsInsertRevision)
                    {
                        run.Font.Color = Color.Blue;
                        run.Font.UnderlineColor = Color.Blue;
                        run.Font.Underline = Underline.Single;
                    }

                    if (run.IsFormatRevision)
                    {
                        run.Font.ClearFormatting();
                        run.Font.Color = Color.Green;
                        run.Font.UnderlineColor = Color.Green;
                        run.Font.Underline = Underline.Single;
                    }
                }
            }

            if (nod.NodeType == NodeType.Cell)
            {
                Cell cellNode = (Cell)nod;

                if (cellNode.FirstParagraph.IsDeleteRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Red;
                }

                if (cellNode.FirstParagraph.IsInsertRevision)
                {
                    cellNode.CellFormat.Shading.BackgroundPatternColor = Color.Blue;
                }

                foreach (Run run in cellNode.GetChildNodes(NodeType.Run, true))
                {
                    if (run.IsDeleteRevision)
                    {
                        run.Font.Color = Color.Red;
                        run.Font.StrikeThrough = true;
                        cellNode.CellFormat.Shading.BackgroundPatternColor = Color.White;
                    }

                    if (run.IsInsertRevision)
                    {
                        run.Font.Color = Color.Blue;
                        run.Font.StrikeThrough = true;
                        cellNode.CellFormat.Shading.BackgroundPatternColor = Color.White;
                    }

                    if (run.IsFormatRevision)
                    {
                        run.Font.UnderlineColor = Color.Green;
                        run.Font.Underline = Underline.Single;
                        cellNode.CellFormat.Shading.BackgroundPatternColor = Color.White;
                    }
                }
            }

            if (nod.NodeType == NodeType.Shape)
            {
                Shape shapeNode = (Shape)nod;

                if (shapeNode.IsDeleteRevision)
                {
                    shapeNode.Font.ClearFormatting();
                    shapeNode.Font.Color = Color.Red;
                    shapeNode.Font.StrikeThrough = true;
                }

                if (shapeNode.IsInsertRevision)
                {
                    shapeNode.Font.ClearFormatting();
                    shapeNode.Font.Color = Color.Blue;
                    shapeNode.Font.Underline = Underline.Single;
                    shapeNode.RemoveAllChildren();
                }
            }
        }

        RtfSaveOptions rtfsvaeopt = new RtfSaveOptions();

        rtfsvaeopt.UseAntiAliasing = true;
        rtfsvaeopt.SaveFormat = SaveFormat.Rtf;

        docOrg.Save(dataDir + "Org-Mod-AsposeOutput.rtf", rtfsvaeopt);