Page 1 of 2

convert hangs on converting pdf to jpg

Posted: 2014-02-18T12:46:33-07:00
by trevororr
I am running Windows Server 2008 using the latest version of ImageMagick. I am converting PDF's to JPG's and re-sizing them down for thumbnails. This works fine for almost all of the PDF's with the exception of a few. With these few when I try to convert them the convert process hangs and climbs to 50% of the CPU usage and never generates the JPG. I have looked at the properties of these few PDF's and compared them to the majority that work and cannot see any difference in the PDF properties.

Here is the command I am running.

"C:\Program Files\ImageMagick\convert.exe" "D:\files\filename.pdf" -resize 216x180 "D:\files\thumbnails\filename.jpg"

How do I go about troubling shooting this?

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T14:27:08-07:00
by dlemstra
Can you add a link to the PDF you are using? And did you install the latest version of GhostScript?

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T14:37:01-07:00
by trevororr
Yes I do have the latest version of GhostScript installed as well. The PDF's are password protected so I don't think my client would approve of me posting them publicly, they are not purchased PDF's but a username and password is required to download them.

Just for kicks I tried other ImageMagick programs like mogrify, composite and montage and they all instantly get to 50% CPU usage and hang.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T14:42:33-07:00
by dlemstra
Did you specify the password for the pdf with -authenticate (http://www.imagemagick.org/script/comma ... thenticate)? The problem seems to be related to the PDF you are using so fixing your problem without it will be difficult. Can you ask your client if you can send it to me personally?

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T14:44:27-07:00
by trevororr
The PDF itself does not have a password, the username / password is on the website. Once authenticated you can download any / all of the PDF's.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T14:57:29-07:00
by trevororr
I just tried using GhostScript to convert the PDF to a JPG and it worked just fine.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T15:10:32-07:00
by dlemstra
Can you ask your client to give permission to send me one PDF file that is failing? With that PDF I can debug our code and figure out what is causing the problem. If this is possible then please send me a PM so we can share email addresses.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T15:18:04-07:00
by fmw42
What is your version of IM and also Ghostscript? Does your pdf have multiple pages with transparency?

Check your delegates.xml file for ps:alpha? Does it use sDevice=pngalpha or pnmraw?


<delegate decode="ps:alpha" stealth="True" command=""gsc" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T15:28:53-07:00
by trevororr
PDF is 1 page, not sure about the transparency though.

ImageMagick: 6.8.8
GhostScript: 9.10

Delegates:
<delegate decode="ps:alpha" stealth="True" command=""@PSDelegate@" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-18T15:29:52-07:00
by fmw42
Look fine to me. I guess the best thing is to send an image to dlemstra.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-19T03:51:57-07:00
by dlemstra
Thank you for sending me the pdf file. The problem seems to be somewhere in GhostScript. It hangs with the following command:

Code: Select all

"C:\program Files (x86)/gs/gs9.10/bin/gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile="output.png" "-finput.pdf"
I can reproduce this on the command line. I think you should file a bug report here: http://bugs.ghostscript.com/

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-19T08:14:22-07:00
by trevororr
Thanks for the help, I will contact GhostScript about this. It must be a specific command line parameter that is causing the hand because I am able to use GhostScript to convert the PDF to a JPG. Maybe I will play around with the parameters to find out which one is the issue.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-19T09:13:55-07:00
by trevororr
Just FYI, if I take out this parameter and change the output device to png16m it works fine.

Code: Select all

-dGraphicsAlphaBits=4
Here is the command that worked for me.

Code: Select all

gswin32c.exe -q -dQUIET -dSAFER -dBATCH -dNOPAUSE  -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitT=2 -sDEVICE=png16m -dTextAlphaBits=4 "-r72x72" -sOutputFile="output.png" "-finput.pdf"

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-20T12:35:47-07:00
by dlemstra
It looks like this bug has been fixed in GhostScript. I creates a correct file when I run the same command on Ubuntu with the latest source code from the git repository of GhostScript. To speak with the famous words of Homer: Mmm... beer.

Re: convert hangs on converting pdf to jpg

Posted: 2014-02-20T12:40:28-07:00
by trevororr
Great, I guess I will have to wait until they release the next windows version before I can use ImageMagick though, for now I am using GhostScript and another program to do what I need but I will go back to ImageMagick when I can.