I am using Comparison for
- GroupDocs.Comparison API version: 23.11.0.
- Development environment details: .NET Framework 4.8
I am testing Word comparison and it detects style of paragraph chang and line break insert change but does not highlight them like it does with Live demos.
- Actual output:
image.png (2.3 KB) - Expect output:
expect.png (1.3 KB) - Source file:
space1.docx (11.5 KB) - Target file:
space2.docx (11.6 KB)
My code:
using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using GroupDocs.Comparison.Result;
using NS_No9.仕様差分分析.Service;
using System.IO;
using System.Linq;
namespace NS_No9.仕様差分分析
{
public static class GroupDocsApi
{
public static ChangeInfo[] compareDoc(string source, string target, string output)
{
// Using Group Docs API to compare word
using (Comparer comparer = new Comparer(source))
{
comparer.Add(target);
// Options for Group Docs API
CompareOptions compareOptions = new CompareOptions()
{
//CalculateCoordinates = true,
MarkChangedContent = true, // Fill color image outline
DetectStyleChanges = true, // Detect style change
ShowDeletedContent = true,
ShowInsertedContent = true,
InsertedItemStyle = new StyleSettings()
{
HighlightColor = System.Drawing.Color.Turquoise,
FontColor = System.Drawing.Color.DarkGreen,
IsUnderline = true,
IsBold = true,
IsItalic = true,
},
DeletedItemStyle = new StyleSettings()
{
HighlightColor = System.Drawing.Color.Red,
},
// Options custom for style change
ChangedItemStyle = new StyleSettings()
{
HighlightColor = System.Drawing.Color.Yellow,
},
GenerateSummaryPage = false,
ExtendedSummaryPage = false,
CompareVariableProperty = true,
//CompareDocumentProperty = true,
CompareBookmarks = true,
//SensitivityOfComparison = 100,
HeaderFootersComparison = true,
CalculateCoordinates = true,
DetalisationLevel = DetalisationLevel.Middle,
MarkNestedContent = true,
WordTrackChanges = false,
ShowRevisions = true,
LeaveGaps = false,
};
// Start compare with options
comparer.Compare(output, compareOptions);
ProcessBar.UpdateProcessBar(40); // Percent for process bar
// Get changes of word
ChangeInfo[] changes = comparer.GetChanges();
FileStream fileStream = null;
fileStream = File.OpenRead(output);
// Path of the temp folder
string tempDirectory = Path.GetTempPath();
// Count pages number of file output word and list page of file output word
Document document = new Document(fileStream);
int pages = document.GetDocumentInfo().PageCount;
int[] pageNumbers = Enumerable.Range(1, pages).ToArray();
// Create preview images of pages
PreviewOptions previewOptions = new PreviewOptions(pageNumber =>
{
var pagePath = Path.Combine(tempDirectory, $"result_{pageNumber}.png");
return File.Create(pagePath);
});
previewOptions.PreviewFormat = PreviewFormats.PNG;
previewOptions.PageNumbers = pageNumbers;
document.GeneratePreview(previewOptions);
fileStream.Close();
ProcessBar.UpdateProcessBar(60); // Percent for process bar
return changes;
}
}
}
}
Thank you,
TrucNV