Identifying and converting a PDF causes delegate to stall

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
MV-jb
Posts: 3
Joined: 2019-02-26T16:02:46-07:00
Authentication code: 1152

Identifying and converting a PDF causes delegate to stall

Post by MV-jb »

Long-time user, first-time poster. I was unable to find a solution to my problem here, so here to create a topic.

We use Windows ImageMagick 6.9.3-8 Q16 x64 to create thumbnails out of the first page of PDFs, and we do so by using x64 GhostScript 9.06 as a delegate, which we configured in the delegates.xml as such:

Code: Select all

<delegate decode="pdf" encode="ps" mode="bi" command="&quot;gswin64c.exe&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=ps2write &quot;-sOutputFile=%o&quot; -- &quot;%i&quot;"/>
Recently, we came across a PDF file (54 pages; ~34MB) that was a bit different than the others, because whenever we tried to run identify and convert on it, the program would stall indefinitely. Running it against GhostScript works as intended, however. I can provide a "-debug all" by request.

We're wondering what would cause the delegate to stall as it does, and how can we get it to un-stall and process the PDF normally, if possible. This is an odd problem for us because no other PDF we've processed had yet to run into this problem. We've tried 7.0.8-28 Q16 x64 to no avail, and while a later version of GhostScript (9.22) solves the problem, we can't upgrade that due to the AGPL license switch.

As an example, here are our arguments for the identify and convert call:

Code: Select all

./identify.exe -format "Format : %m 
Dimension : %G 
IccProfile : %[profile:icc] 
Colorspace : %[colorspace] 
Opaque : %[opaque] 
X Resolution: %x 
Y Resolution: %y 
" "test1.png" -quiet

Code: Select all

./convert.exe -auto-orient -density 72 -units PixelsPerInch test1.pdf[0] -thumbnail 350x350> -profile "IccProfiles\sRGB-IEC61966-2.1.icc" -flatten -verbose test1.jpg
I appreciate your time in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identifying and converting a PDF causes delegate to stall

Post by fmw42 »

I am no expert on this, but process the pdf with Ghostscript and get is command line that it uses or you use. Then change the delegates.xml file to use those same arguments.

Also perhaps you should post a link to your problematic PDF file so the IM developers can test with it.
MV-jb
Posts: 3
Joined: 2019-02-26T16:02:46-07:00
Authentication code: 1152

Re: Identifying and converting a PDF causes delegate to stall

Post by MV-jb »

I'm afraid I won't be able to provide the PDF file. As counterproductive as it sounds, it belongs to a client and it's subject to privacy law, so the best I can do is provide debug logs. All I can say for sure though is that the PDF was a slide conversion from a PPTX file from Office 365. I can see if I can create a test file out of that.

The following is what we use when we execute GhostScript directly. I would have to do some trial and error to see which delegate I have to change to confirm that your suggestion works. Given that a version change was all that it required to fix the issue, I'm not sure changing the arguments will solve the issue.

Code: Select all

./gswin64c.exe -dNOPAUSE -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=png16m -o test1.jpg -r300x300 -sPAPERSIZE=a4 test1.pdf
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identifying and converting a PDF causes delegate to stall

Post by fmw42 »

Have you tried converting in ImageMagick without the resize and the profile. Perhaps the issue is with one of those operations and not Ghostscript.
MV-jb
Posts: 3
Joined: 2019-02-26T16:02:46-07:00
Authentication code: 1152

Re: Identifying and converting a PDF causes delegate to stall

Post by MV-jb »

I tried removing the resize and the profile options and it didn't work, but followed a different lead that I had ignored earlier. In the debug logs, this appears...

Code: Select all

2019-02-27T09:45:14-08:00 0:01.641 1.547u 6.9.3 Configure convert.exe[13764]: nt-base.c/NTLocateGhostscript/1127/Configure
  Ghostscript ((null)) version 0.00
2019-02-27T09:45:14-08:00 0:01.646 1.547u 6.9.3 Configure convert.exe[13764]: nt-base.c/NTLocateGhostscript/1127/Configure
  Ghostscript (GPL Ghostscript) version 8.15
2019-02-27T09:45:14-08:00 0:01.652 1.547u 6.9.3 Configure convert.exe[13764]: nt-base.c/NTGhostscriptGetString/1226/Configure
  registry: "HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\8.15\GS_DLL"="C:\Program Files (x86)\GPLGS\gsdll32.dll"
2019-02-27T09:45:14-08:00 0:01.659 1.547u 6.9.3 Policy convert.exe[13764]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Delegate; rights=Execute; pattern="gswin64c.exe" ... <stalls here>
I noticed that somehow the portable version of ImageMagick tried to find the GhostScript DLLs through the registry. While we placed the GhostScript executables and DLLs in the same directory as our ImageMagick executables without installing, it locates the DLLs and uses them first before running the executable (if it can't find the DLLs). Correct me if my understanding here is wrong.

So I installed GhostScript 9.06, and got this result instead:

Code: Select all

2019-02-27T09:53:45-08:00 0:01.693 1.563u 6.9.3 Configure convert.exe[56236]: nt-base.c/NTLocateGhostscript/1127/Configure
  Ghostscript (GPL Ghostscript) version 9.06
2019-02-27T09:53:45-08:00 0:01.697 1.563u 6.9.3 Configure convert.exe[56236]: nt-base.c/NTGhostscriptGetString/1226/Configure
  registry: "HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\9.06\GS_DLL"="C:\Program Files\gs\gs9.06\bin\gsdll64.dll"
2019-02-27T09:53:46-08:00 0:02.216 2.047u 6.9.3 Resource convert.exe[56236]: resource.c/RelinquishUniqueFileResource/1042/Resource
  Relinquish C:/Users/JASON~1.BOL/AppData/Local/Temp/magick-56236v5ujg3BXR1GJ
2019-02-27T09:53:46-08:00 0:02.226 2.047u 6.9.3 Exception convert.exe[56236]: utility.c/ShredFile/1822/Exception
  Failed to remove: C:/Users/JASON~1.BOL/AppData/Local/Temp/magick-56236v5ujg3BXR1GJ.cache
2019-02-27T09:53:46-08:00 0:02.232 2.047u 6.9.3 Resource convert.exe[56236]: resource.c/RelinquishUniqueFileResource/1042/Resource
  Relinquish C:/Users/JASON~1.BOL/AppData/Local/Temp/magick-56236bOp-phL46x-D
2019-02-27T09:53:46-08:00 0:02.248 2.047u 6.9.3 Exception convert.exe[56236]: utility.c/ShredFile/1822/Exception
  Failed to remove: C:/Users/JASON~1.BOL/AppData/Local/Temp/magick-56236bOp-phL46x-D.cache
2019-02-27T09:53:46-08:00 0:02.258 2.047u 6.9.3 Policy convert.exe[56236]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="C:/Users/JASON~1.BOL/AppData/Local/Temp/magick-56236IH5fr7du1bdQ1" ...
2019-02-27T09:53:46-08:00 0:02.265 2.047u 6.9.3 Blob convert.exe[56236]: blob.c/OpenBlob/2594/Blob
    read 3 magic header bytes
2019-02-27T09:53:46-08:00 0:02.277 2.047u 6.9.3 Cache convert.exe[56236]: cache.c/DestroyPixelCache/999/Cache
  destroy
2019-02-27T09:53:46-08:00 0:02.290 2.047u 6.9.3 Policy convert.exe[56236]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Coder; rights=Read; pattern="PNG" ...
2019-02-27T09:53:46-08:00 0:02.303 2.047u 6.9.3 Coder convert.exe[56236]: png.c/ReadPNGImage/3907/Coder
  Enter ReadPNGImage() <continues as normal>
ImageMagick identify and convert is now working for me, but this does bring up the question: "Is it possible to manually set the GhostScript DLL paths, or will it always only check the registry for them?". The other thing I'm scratching my head on is why this only affects this specific PDF and not others :? Is it usually better to have ImageMagick get the DLLs instead of running the executable? It seems from this observation that this is the case.

If manually setting the DLL paths is not possible with ImageMagick, I'll see if tweaking the registry will, using the same path as the locator.
Post Reply