Png generated by Pdf file using Magick.Net is black #695

354 views Asked by At

I have created a small .net core 3.1 console application to convert pdf to png using Magick.Net (https://www.nuget.org/packages/Magick.NET-Q16-AnyCPU/). I have also installed ghostscript public license. It's doing alright but the output image is totally black and I can't read a single line. If I open the file using Paint then it's fine. Here is my code:

        public static int ConvertFileToImages(string filePath, string destinationPath)
        {
            int noofPages = 0;
            MagickReadSettings magickReadSettings = new MagickReadSettings();
            magickReadSettings.Density = new Density(300, 300);
            using (MagickImageCollection magickImageCollection = new MagickImageCollection())
            {
                magickImageCollection.Read(filePath, magickReadSettings);
                int page = 1;
                noofPages = magickImageCollection.Count;
                foreach (MagickImage magickImage in magickImageCollection)
                {
                    magickImage.Format = MagickFormat.Png;
                    magickImage.BackgroundColor = MagickColors.White;
                    string imageFilePath = string.Concat(destinationPath, "file-", page, ".png");
                    magickImage.Write(imageFilePath);
                    page++;
                }
            }
            return noofPages;
        }

Am I doing anything wrong?

0

There are 0 answers