Getting error/pdf.c/ReadPDFImage/788 From Example Code

Apr 29, 2015 at 1:27 PM
Hi,

I'm trying to get the example here working on my machine. I get the following exception:
An unhandled exception of type 'ImageMagick.MagickDelegateErrorException' occurred in Magick.NET-Q8.Wrapper-x86.dll

Additional information: PDF PoC Revisited.vshost.exe: PDFDelegateFailed `The system cannot find the file specified.

' @ error/pdf.c/ReadPDFImage/788
The point of the exception:

Image

What the Q8-AnyCPU zip gave me:

Image

The project build settings and references expanded:

Image

Magick.NET-AnyCPU properties;

Image

Magick.NET.Core properties:

Image

The bin\Debug folder on my machine:

Image

The runtime value of the pdfLocation variable:

Image

Please advise, thanks!
Coordinator
Apr 29, 2015 at 2:25 PM
Edited Apr 29, 2015 at 2:26 PM
Did you install Ghoscript? If you did you are probably experiencing the same issue that has been reported here: https://magick.codeplex.com/discussions/632560. A new release will be published soon.
Apr 29, 2015 at 2:38 PM
I did, indeed, install Ghostscript. An interesting development, though, is that I can get it working fine with the x64 libraries. If I create a new project, target x64 in the Build menu, and use the x64 libraries, I can do a straight copy/paste of code from the AnyCPU project to the x64 project and it works as expected. However, I can't do parallel operations with the x64 libraries. By parallel operations, I mean take all the business logic from Main, wrap it in an Action with a lambda, and execute a Parallel.Invoke using the TPL passing in the same action twice. So, there could be two additional scenarios that might help shed light as to what's going on.

Lambda example:
Action<int> task = (int num) => { ...everything from main...};

Parallel.Invoke(() => {task(1);}, () => {task(2);});
Coordinator
Apr 29, 2015 at 2:46 PM
You probably installed the 64 bit version of Ghostscript. If the platform of Ghostscript matches the platform of your application it will load the Ghoscript dll. And it will use the command line if they don't match. And when you execute Ghostscript in a multi-threaded environment only the first thread can use the library. The rest will execute the command line and that is broken in the current version of Magick.NET.
Apr 29, 2015 at 3:04 PM
Edited Apr 29, 2015 at 3:05 PM
You are correct on the version of Ghostscript I installed. I installed the 32 bit version and it executed the Read method fine. It generated yet another error, though. Do you want that here or in a new thread?

Also, is there an ETA on the command line fix? Thank you very much already.
Coordinator
Apr 29, 2015 at 3:07 PM
You can continue the conversation here. I am hoping to publish a new release this week.
Apr 29, 2015 at 3:11 PM
The new exception says
An unhandled exception of type 'ImageMagick.MagickCoderErrorException' occurred in Magick.NET-Q8.Wrapper-x86.dll

Additional information: PDF PoC Revisited.vshost.exe: WriteBlob Failed `c:\users\xxxx\documents\visual studio 2013\Projects\PDF PoC Revisited\PDF PoC Revisited\bin\Debug\Image Extract\Terms of Service.Page1.150DPI.png' @ error/png.c/MagickPNGErrorHandler/1650
All my code from main:
            var imageOutputDpi = 150;

            var magickSettings = new MagickReadSettings();
            magickSettings.Density = new PointD(imageOutputDpi, imageOutputDpi);
            magickSettings.Format = MagickFormat.Png;
            magickSettings.ColorSpace = ColorSpace.GRAY;

            using(var imageCollection = new MagickImageCollection())
            {
                var assemblyLocation = Assembly.GetExecutingAssembly().Location;
                var assemblyDirectory = assemblyLocation.Remove(assemblyLocation.LastIndexOf('\\') + 1);
                var pdfFileName = "Terms of Service Agreement 2014";
                var pdfLocation = string.Format("{0}{1}{2}", assemblyDirectory, pdfFileName, ".pdf"); //[Assembly Directory]\Terms of Service Agreement 2014.pdf

                if (File.Exists(pdfLocation)) imageCollection.Read(pdfLocation, magickSettings);

                var outputFolderName = "Image Extract";
                var pdfOutputDirectory = string.Format("{0}{1}\\", assemblyDirectory, outputFolderName); //[Assembly Directory]\Image Extract\
                var pdfOutputPostfixFormat = ".Page{0}.{1}DPI";

                var pageNumber = 1;
                foreach (var image in imageCollection)
                {
                    var pdfOutputPostfix = string.Format(pdfOutputPostfixFormat, pageNumber, imageOutputDpi); //.Page1.150DPI
                    var imageOutputLocation = string.Format("{0}{1}{2}{3}", pdfOutputDirectory, "Terms of Service", pdfOutputPostfix, ".png"); //[Assembly Directory]\Image Extract\Terms of Service.Page1.150DPI.png
                    image.Write(imageOutputLocation);

                    pageNumber++;
                }
            }

            Console.WriteLine("done");
            Console.Read();
Apr 29, 2015 at 3:16 PM
Nevermind on that above exception. I just had to manually create the folder. That's manageable. It appears I'm good to go here. Thank you again! I'll look for the new release later this week.
Nov 25, 2015 at 11:24 AM
stranger57 wrote:
I did, indeed, install Ghostscript. An interesting development, though, is that I can get it working fine with the x64 libraries. If I create a new project, target x64 in the Build menu, and use the x64 libraries, I can do a straight copy/paste of code from the AnyCPU project to the x64 project and it works as expected. However, I can't do parallel operations with the x64 libraries. By parallel operations, I mean take all the business logic from Main, wrap it in an Action with a lambda, and execute a Parallel.Invoke using the TPL passing in the same action twice. So, there could be two additional scenarios that might help shed light as to what's going on.

Lambda example:
Action<int> task = (int num) => { ...everything from main...};

Parallel.Invoke(() => {task(1);}, () => {task(2);});
Hi!

Is there any progress on calling ghostscript by multiple threads?

Best Regards!
Coordinator
Nov 25, 2015 at 12:55 PM
The latest release includes a multi-threading fix for Ghostscript. Can you upgrade to 7.0.0.0022 and test if you can reproduce the issue?