Image comparison processing time to save output image is too long in .NET

  • About 1-2 minutes to export a image

  • Result saved image
    image.png (6.0 KB)

  • My code:

    public static class GroupDocsApi
    {
        // Function use GroupDocs API to compare words
        public static ChangeInfo[] CompareDoc(string source, string target, string outPut)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            var assembly = Assembly.GetExecutingAssembly();

            // Check the resource name for your license file
            string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("GroupDocs.Comparison.NET.lic"));
            Console.WriteLine("Path: {0}.", resourceName);

            // Load license from embedded resource
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                if (stream != null)
                {
                    License license = new License();
                    license.SetLicense(stream);
                }
                else
                {
                    throw new FileNotFoundException("License file not found as embedded resource.");
                }
            }

            Console.WriteLine("Start calculate process time API....");
            // 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()
                {
                    //MarkNestedContent = true,
                    GenerateSummaryPage = false,
                    MarkChangedContent = true,
                    DetectStyleChanges = true,
                    CompareBookmarks = false,
                    ChangedItemStyle = new StyleSettings()
                    {
                        HighlightColor = System.Drawing.Color.Yellow,
                        ShapeColor = System.Drawing.Color.LightYellow,
                    },
                    InsertedItemStyle = new StyleSettings()
                    {
                        HighlightColor = System.Drawing.Color.Aqua,
                        ShapeColor  = System.Drawing.Color.Blue,
                    },
                    DeletedItemStyle = new StyleSettings()
                    {
                        HighlightColor = System.Drawing.Color.Red,
                        ShapeColor= System.Drawing.Color.LightCoral,
                    },

                    DetalisationLevel = DetalisationLevel.High
                    //ShowDeletedContent = false,
                    //ShowInsertedContent = false,
                };

                // Start compare with options
                comparer.Compare(outPut, compareOptions);

                stopwatch.Stop();
                TimeSpan elapsedTime = stopwatch.Elapsed;
                Console.WriteLine("Time process API: " + elapsedTime.ToString());

                ProcessBar.UpdateProcessBar(60);    // Percent for process bar

                // Get changes of word
                ChangeInfo[] changes = comparer.GetChanges();

                int[] pageNumbers = Functions.GroupChangesByPage(changes).Keys.ToArray();

                Stopwatch stopwatch1 = new Stopwatch();
                stopwatch1.Start();

                CreatePageImage(outPut, pageNumbers);

                stopwatch1.Stop();
                TimeSpan elapsedTime1 = stopwatch1.Elapsed;
                Console.WriteLine("Time process create images: " + elapsedTime1.ToString());

                return changes;
            }
        }

        public static void CreatePageImage(string outPut, int[] pageNumbers)
        {
            FileStream fileStream = null;
            try
            {
                fileStream = File.OpenRead(outPut);
                Document document = new Document(fileStream);
                string folderTempPath = Storage.FolderTempPath;
                PreviewOptions previewOptions = new PreviewOptions(pageNumber =>
                {
                    var pagePath = Path.Combine(folderTempPath, $"result_{pageNumber}.png");
                    return File.Create(pagePath);
                });
                previewOptions.PreviewFormat = PreviewFormats.PNG;
                previewOptions.PageNumbers = pageNumbers;
                document.GeneratePreview(previewOptions);
            }
            finally
            {
                ProcessBar.UpdateProcessBar(80);    // Percent for process bar
                fileStream.Close();
            }
        }
    }

@FPT008

Could you please share following details and we’ll investigate this issue:

  • GroupDocs.Comparison for .NET API version
  • Sample/problematic source and target files

API Version is GroupDocs.Comparison 24.12.1-alpha-20250110063050
@atir.tahir

@FPT008

Could you please also share the source/target files using that issue could be reproduced?