No such file or directory @ error/pdf.c/ReadPDFImage/713

May 29, 2014 at 3:43 PM
Edited May 29, 2014 at 3:47 PM
Hi again!

I'm using Magick.NET-6.8.8.1001-Q16-AnyCPU-net40-client to convert a pdf to png.

I have the following code to do it:
Dim settings As New MagickReadSettings()
                    settings.Density = New MagickGeometry(300, 300)

                    Using images As New MagickImageCollection()
                        images.Read(sPlantillaRellena, settings)
                        Dim horizontal As MagickImage = images.AppendHorizontally()
                        horizontal.Write(sRutaImagen)
                        images.Dispose()
                    End Using
                    settings = Nothing
The 'sPlantillaRellena' variable is the pdf saved in a shared folder in a server and the 'sRutaImagen' variable is the png to be saved in a shared folder in a server.

I have already Ghostscript 9.14 for Windows 64 bit.

This code is working until today. But today, the application show the next error:
Magick: PostscriptDelegateFailed `\\carpetaCompartida\file_fill_1.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/713
We run the application in IIS 7 and we have an application pool, which is recycled every nigth.

What could be the problem?

Thanks in advance.
Coordinator
May 29, 2014 at 9:26 PM
Can you upgrade to the latest version and try again? You should get a better error message in the latest version.
May 30, 2014 at 6:15 AM
Hi!

The latest version is the one I have, at least in http://www.ghostscript.com/download/gsdnld.html the latest versión is 9.14.

Thanks in advance.
Coordinator
May 30, 2014 at 6:39 AM
I meant the latest version of Magick.NET, the version you are using is not the latest.
May 30, 2014 at 7:44 AM
Hi again!

I have updated to the latest version and I haven't get the previous error, but now when I run the application in two different computers I get this error Object reference not set to an instance of an object when I create Dim horizontal As MagickImage = images.AppendHorizontally()
I have checked that the 'images' object is not nothing and the pdf is also created.

What could be the problem?

Thanks in advance.
Coordinator
May 30, 2014 at 8:09 AM
I just added a simple unit test to see if there was a problem with the AppendHorizontally but that seems to work correctly. Are you using the collection after it has been Disposed? For example this:
Using images As New MagickImageCollection()
  images.Read(sPlantillaRellena, settings)
  images.Dispose() ' You also don't need to do this because of the using statement...
  Dim horizontal As MagickImage = images.AppendHorizontally()
  horizontal.Write(sRutaImagen)
End Using
May 30, 2014 at 8:21 AM
No, I don't use the collection after it has been disposed. In fact, I put 'images.Dispose()' when occurs the first error in case it could be a memory problem.

Actually, I run the application without 'images.Dispose()' and I get the same error (Object reference not set to an instance of an object) in the same line.
Dim settings As New MagickReadSettings()
settings.Density = New MagickGeometry(300, 300)
Using images As New MagickImageCollection()
    images.Read(sPlantillaRellena, settings)
    Dim horizontal As MagickImage = images.AppendHorizontally()
    horizontal.Write(sRutaImagen)  
End Using
Thanks.
Coordinator
May 30, 2014 at 8:24 AM
Can you add a link to your PDF or contact me through CodePlex (on my profile page) so I can see if I can reproduce the problem.
May 30, 2014 at 8:38 AM
Hi!

I send you a message in CodePlex.
Coordinator
May 30, 2014 at 3:06 PM
I tried to read your PDF and I can create a PNG with the following code in a console application:
static void Main(string[] args)
{
  MagickReadSettings settings = new MagickReadSettings();
  settings.Density = new MagickGeometry(300, 300);
  using (MagickImageCollection images = new MagickImageCollection())
  {
    images.Read(@"Hoja_Trabajo_2.pdf", settings);
    MagickImage horizontal = images.AppendHorizontally();
    horizontal.Write(@"Hoja_Trabajo_2.png");
  }
}
It looks like the problem is somewhere else in your code. Have you tried to put the code from your example in a console application?
Jun 4, 2014 at 2:25 PM
Hi again dlemstra!

I have tried the code in a console application. Precisely, I have created two console application, in one I work with the variable "Hoja_trabajo_1.pdf", and in the other I work with the variable "Hoja_trabajo_2.pdf". If I run the two console applications at the same time, it works, that is, it has been created "Hoja_trabajo_1.png" and "Hoja_trabajo_2.png".

Until this point, the application works fine.

But at the moment, when I put the code in two web applications (one for "Hoja_Trabajo_1.pdf" and other for "Hoja_Trabajo_2.pdf") and I run these applications under the same application pool in a IIS 7, I get this error Object reference not set to an instance of an object when I create Dim horizontal As MagickImage = images.AppendHorizontally() again.

I also prove to run these applications under different application pools. In this case, it works fine.

What could be the problem?

Thanks in advance.
Coordinator
Jun 4, 2014 at 8:16 PM
Edited Jun 4, 2014 at 8:16 PM
I think Ghostscript will not work when the library is shared between application pool. Can you reproduce the problem if you convert a .jpg file to a .png file? I think it is better to not share the same application pool. When we deploy sites at my company we always create a new application pool for a website.
Jun 13, 2014 at 11:09 AM
Hi dlemstra!

I have tried this: I have created one application which has two parameters, one for the .pdf file and the other one for the .png file.

This application is being running under the same application pool. We only have one application pool because several people work with the same application (is one application for all people), for this we can't create one application pool for each person.

If I put in the parameters that I have to convert a .jpg to a .png file and on one IE put "hoja_trabajo_1.jpg" to "hoja_trabajo_2.png" and on another IE punt "hoja_trabajo_2.jpg" to "hoja_trabajo_2.png", it works perfectly.

But in the moment that I have to convert a .pdf file to .png file, it doesn't work (it produces the same error I have explained you).

We have to convert a .pdf file to an image, do you know what is going on? And do you know a possible solution?

Thanks in advance.
Aug 22, 2014 at 9:24 PM
I'm experiencing this exact same issue starting with the first error "No such file or directory" and now getting "Object reference not set to an instance of an object" when converting a PDF to a png vertically. Did you guys resolve this?
                        ImageMagick.MagickImage vertical = images.AppendVertically();
                        vertical.Write(destinationFilePath);
Coordinator
Aug 22, 2014 at 9:35 PM
The problem was that the directory that contains Ghostscript could not be found. Can you try the following:
MagickNET.SetGhostscriptDirectory("C:\\Program Files\\gs\\gs9.14\\bin");
Not sure if you use the same version/platform of Ghostscript so you might have to change the path.
Aug 22, 2014 at 9:59 PM
Thanks for the quick response. That didn't fix it. Still getting the same object reference error.

I bet the issue is that I'm using the x86 DLL. I started this project earlier this year and couldn't get the x64 one to work and the 32 bit worked great. Now that I'm deploying the project to the server I'm running into these errors. Do you suggest that I try to get it working on x64? It's hosted on Windows Server 2008 64 bit. I am using the latest x86 though running the web service in IIS in it's own application pool with 32-Bit enabled.
Coordinator
Aug 22, 2014 at 10:03 PM
Did you install the 32 bit version of Ghostscript on your server? You should use C:\Program Files (x86)\gs\gs9.14\bin as the path if you did. And if you installed the x64 version of Ghostscript I would suggest you to change to the x86 version. It is better to keep the platforms the same,
Aug 22, 2014 at 10:20 PM
Yeah, I tried both. C:\Program Files (x86)\ & C:\Program Files\ with the same result/error.

I have both versions of GhostScript installed on my dev machine and on the server but using the x86 Magick.Net dll. I'm going to uninstall everything and start fresh and try to get x64 working. It is odd that it works fine on my dev machine but not on the server. I'll update this thread with the results. . . .
Coordinator
Aug 22, 2014 at 10:22 PM
Turning on debug logging might also give you some more information: https://magick.codeplex.com/wikipage?title=Detailed%20debug%20information&referringTitle=Documentation,
Aug 25, 2014 at 10:35 PM
Ok, I'm not safely able to change all solutions and projects to 64 bit on this large legacy system I'm working in where this library will be referenced. I enabled logging and provided the log output here. The logs with "**********" are my own separation logs so I know which lines of code trigger logs. As soon as the code runs "vertical.Write(destinationFilePath);" there are no additional logs. An exception is thrown "Object reference not set to an instance of an object.". The code runs fine on my local dev machine. I have the latest version of GhostScript 32 bit installed on the server and the C++ Redistributable update for VS 2012.

I really appreciate your help. Thanks.


************ images.Read(sourceFilePath, settings); ***********
Policy: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Policy w3wp.exe[1636]: policy.c/IsRightsAuthorized/577/Policy
Domain: Path; rights=Read; pattern="\webtest02\Web\Sites\Contracts\2014\8\22\600047942_140800068_9999_3.pdf" ...
Blob: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Blob w3wp.exe[1636]: blob.c/OpenBlob/2540/Blob read 3 magic header bytes
Cache: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Cache w3wp.exe[1636]: cache.c/DestroyPixelCache/905/Cache destroy
Policy: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Policy w3wp.exe[1636]: policy.c/IsRightsAuthorized/577/Policy
Domain: Coder; rights=Read; pattern="PDF" ...
Policy: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Policy w3wp.exe[1636]: policy.c/IsRightsAuthorized/577/Policy
Domain: Path; rights=Read; pattern="\webtest02\Web\Sites\Contracts\2014\8\22\600047942_140800068_9999_3.pdf" ...
Blob: 2014-08-25T15:58:23-06:00 6:44.734 27.768u 7.0.0 Blob w3wp.exe[1636]: blob.c/OpenBlob/2540/Blob read 3 magic header bytes
Cache: 2014-08-25T15:58:24-06:00 6:44.750 27.768u 7.0.0 Cache w3wp.exe[1636]: cache.c/DestroyPixelCache/905/Cache destroy
Policy: 2014-08-25T15:58:24-06:00 6:44.750 27.768u 7.0.0 Policy w3wp.exe[1636]: policy.c/IsRightsAuthorized/577/Policy
Domain: Path; rights=Read; pattern="\webtest02\Web\Sites\Contracts\2014\8\22\600047942_140800068_9999_3.pdf" ...
Blob: 2014-08-25T15:58:24-06:00 6:44.750 27.768u 7.0.0 Blob w3wp.exe[1636]: blob.c/OpenBlob/2540/Blob read 3 magic header bytes
Resource: 2014-08-25T15:58:24-06:00 6:44.750 27.768u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/468/Resource...
Resource: 2014-08-25T15:58:24-06:00 6:44.750 27.768u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/509/Resource
C:/Windows/TEMP/magick-1636q4nas3V5-VDS
Resource: 2014-08-25T15:58:24-06:00 6:44.765 27.784u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/468/Resource...
Resource: 2014-08-25T15:58:24-06:00 6:44.765 27.784u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/509/Resource
C:/Windows/TEMP/magick-1636jHSOVcPuwdTo
Resource: 2014-08-25T15:58:24-06:00 6:44.765 27.784u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/468/Resource...
Resource: 2014-08-25T15:58:24-06:00 6:44.765 27.784u 7.0.0 Resource w3wp.exe[1636]: resource.c/AcquireUniqueFileResource/509/Resource
C:/Windows/TEMP/magick-16366Q0k7X3KqyqK
Resource: 2014-08-25T15:58:24-06:00 6:44.765 27.784u 7.0.0 Resource w3wp.exe[1636]: resource.c/RelinquishUniqueFileResource/893/Resource
C:/Windows/TEMP/magick-16366Q0k7X3KqyqK
Resource: 2014-08-25T15:58:25-06:00 6:45.904 28.923u 7.0.0 Resource w3wp.exe[1636]: resource.c/RelinquishUniqueFileResource/893/Resource
C:/Windows/TEMP/magick-1636jHSOVcPuwdTo
Resource: 2014-08-25T15:58:25-06:00 6:45.904 28.923u 7.0.0 Resource w3wp.exe[1636]: resource.c/RelinquishUniqueFileResource/893/Resource
C:/Windows/TEMP/magick-1636q4nas3V5-VDS
Cache: 2014-08-25T15:58:25-06:00 6:45.904 28.923u 7.0.0 Cache w3wp.exe[1636]: cache.c/DestroyPixelCache/905/Cache destroy
************ ImageMagick.MagickImage vertical = images.AppendVertically(); ***********
************ vertical.Write(destinationFilePath); ***********
Object reference not set to an instance of an object.
Coordinator
Aug 26, 2014 at 8:48 AM
Is it possible for you to create a crashdump? This will make it easier for me to investigate the problem. The call to DestroyPixelCache makes it look like the image could not be read properly. I will add some more checks to make sure the image has been read properly. This could also explain the 'Object reference not set to an instance of an object' error.