Hello Support
I am trying to compare two rtf files, Please see attached zip NumberLoss.zip (30.5 KB)
with UCO as original file UCM as modified file UC-Word as word compare output and UC-AsposeOutput as Aspose output.
Code used is below, Please note that for deleted content and added content, we are looping through nodes and adding colour and style. This is because in RTF fromat deleted content is not seen as strikeout. For images and ole objects we are adding bookmarks and during rendering we are overlaying images.
Please open files using Wordpad and not MS Word to see the difference.
We need to get numbering similar to that of word output. Your help is much appreciated.
Thanks in advance
string sAuthor = "";
int i=0;
int j=0;
Document docOrg = new Document("D:\\Compare\\UCO.rtf");
Document doc=new Document("D:\\Compare\\UCM.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 = true;
options.IgnoreHeadersAndFooters = true;
docOrg.LayoutOptions.RevisionOptions.ShowRevisionBalloons = false;
docOrg.LayoutOptions.RevisionOptions.ShowOriginalRevision = true;
docOrg.LayoutOptions.RevisionOptions.RevisedPropertiesColor = Aspose.Words.Layout.RevisionColor.Green;
docOrg.LayoutOptions.RevisionOptions.RevisedPropertiesEffect = Aspose.Words.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);
RtfSaveOptions rtfsvaeopt = new RtfSaveOptions();
rtfsvaeopt.UseAntiAliasing = true;
rtfsvaeopt.SaveFormat = SaveFormat.Rtf;
DocumentBuilder builder = new DocumentBuilder(docOrg);
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.UnderlineColor = Color.Blue;
run.Font.Underline = Underline.Single;
//cellNode.CellFormat.Shading.BackgroundPatternColor = Color.White;
}
if (run.IsFormatRevision)
{
//run.Font.ClearFormatting();
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)
{
builder.MoveTo(shapeNode);
builder.StartBookmark("BK_DD" + i.ToString());
builder.EndBookmark("BK_DD" + i.ToString());
i=i+1;
//shapeNode.Font.ClearFormatting();
//shapeNode.Font.Color = Color.Red;
//shapeNode.Font.StrikeThrough = true;
}
if (shapeNode.IsInsertRevision)
{
builder.MoveTo(shapeNode);
builder.StartBookmark("BK_DI" + i.ToString());
builder.EndBookmark("BK_DI" + i.ToString());
j=j+1;
//shapeNode.Font.ClearFormatting();
//shapeNode.Font.Color = Color.Blue;
//shapeNode.Font.Underline = Underline.Single;
//shapeNode.RemoveAllChildren();
}
}
}
docOrg.Save("D:\\Compare\\UC-AsposeOutput.rtf", rtfsvaeopt);
}
Regards
Mandar