Ejemplo n.º 1
0
        static int Split(string whichPdf, string outputPath)
        {
            var settings = new MagickReadSettings();

            // Settings the density to 300 dpi will create an image with a better quality
            settings.Density = new PointD(300, 300);

            using (var images = new MagickImageCollection())
            {
                // Add all the pages of the pdf file to the collection
                images.Read(whichPdf, settings);

                int pageNumber = 0;
                foreach (MagickImage image in images)
                {
                    pageNumber++;

                    // Write page to file that contains the page number
                    image.Write(Path.Combine(outputPath, PageComparison.CreatePageFileName(pageNumber)));

                    // Write a thumbnail for the page
                    image.Resize(ThumbnailGeometry);
                    image.Write(Path.Combine(outputPath, PageComparison.CreateThumbnailFileName(pageNumber)));
                }

                return(pageNumber);
            }
        }
Ejemplo n.º 2
0
        private static IEnumerable <PageComparison> Compare(int numPages, string rootPath, string referencePath, string toTestPath, string comparePath)
        {
            for (var currentPage = 1; currentPage <= numPages; currentPage++)
            {
                var currentComparison = new PageComparison()
                {
                    PageNumber = currentPage,
                    RootPath   = rootPath
                };

                using (var referenceImage = new MagickImage())
                    using (var testImage = new MagickImage())
                        using (var compareImage = new MagickImage())
                        {
                            var referenceImagePath = currentComparison.ReferencePagePath;
                            if (File.Exists(referenceImagePath))
                            {
                                referenceImage.Read(referenceImagePath);
                            }

                            var testImagePath = currentComparison.TestPagePath;
                            if (File.Exists(testImagePath))
                            {
                                testImage.Read(testImagePath);
                            }

                            InsertEmptyImageIfNecessary(referenceImage, testImage);
                            InsertEmptyImageIfNecessary(testImage, referenceImage);

                            EnsureImageIsColored(referenceImage);
                            EnsureImageIsColored(testImage);

                            var result = referenceImage.Compare(testImage, ErrorMetric.Absolute, compareImage, Channels.All);

                            compareImage.Write(currentComparison.ComparePagePath);
                            compareImage.Resize(ThumbnailGeometry);
                            compareImage.Write(currentComparison.ComparePageThumbnailPath);

                            currentComparison.ComparisonScore = result;
                            currentComparison.PixelCount      = referenceImage.Height * referenceImage.Width;
                        }

                yield return(currentComparison);
            }
        }
Ejemplo n.º 3
0
 private static string ImageLink(string which, PageComparison page)
 {
     return($"[![{which}]({which}/Thumb{page.PageNumber:0000}.png \"{which}\")]({which}/Page{page.PageNumber:0000}.png)");
 }