Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: PDF to PNG conversion quite slow

$
0
0
I am using Magick.NET in a multi-threaded WPF application to convert PDFs to PNGs in batches of thousands. The application gets all the documents from a database and then the threads take out the documents one by one from a concurrent queue. This works very good with small documents, but with the large documents (going as big as 10-15MB), it takes quite a lot of time.

When I try to convert these particular files one by one, they are relatively quite fast. I am not sure what is causing the conversion to run slower when there are a few more threads running, trying to achieve the same thing. I was also testing my CPU usage and during the conversion of a large file, my CPU usage drops significantly.

With smaller files, the conversion runs smoothly with around 90-100% CPU usage but when the application picks up a larger file, it will drop to around 50-60% for a few seconds and then go back up and might drop again. I have over a million documents to convert and would like to know how, if possible, I can improve the performance.

I am using an Intel Xeon CPU E5-1607 0 @ 3.00GHz running Windows 7 64 bit with 8GB RAM and Radeon HD 5450.

Below is a part of my conversion code that runs on different threads:
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new MagickGeometry(150, 150);

        // Read the PDF into a collection of images
        images.Read(currentDocument.OriginalPath, settings);

        int page = 1;
        string destinationPath = "C:\\Test\\" + fileNameWithoutExtension;

        // Create the directory if it does not exist.
        if (!Directory.Exists(destinationPath))
        {
            Directory.CreateDirectory(destinationPath);
        }

        foreach (MagickImage image in images)
        {
           // Formatting image
           image.Format = MagickFormat.Png;
           image.Alpha(AlphaOption.Remove);
           image.Annotate("Some Watermark", Gravity.Southwest);
           if (image.BaseWidth > image.BaseHeight)
           {
                    image.Resize(1000, 0);
           }
           else
           {
                     image.Resize(0, 1000);
           }

           image.Quality = 100;
           image.Enhance();
           image.Normalize();
           QuantizeSettings quantizeSettings = new QuantizeSettings();
           quantizeSettings.Colors = 250;
           image.Quantize(quantizeSettings);

           // Write the image to the specified path as a PNG
           image.Write(destinationPath + "\\" + page.ToString() + ".png");
        }
Thanks a lot.

Viewing all articles
Browse latest Browse all 3693

Trending Articles