Pdf to jpg conversion not working for some pdfs.

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
diligentG
Posts: 5
Joined: 2017-06-20T06:56:52-07:00
Authentication code: 1151

Pdf to jpg conversion not working for some pdfs.

Post by diligentG »

Hello,

I'm new to imageMagcik and I'm having some issue regarding it.
I'm using IM to convert pdf pages to images(jpg), and it's working properly fine at my local system. But when i'm testing on godaddy server it's not working. It increases the CPU usage( I don't if it's related or not ). And this is happening only for few pdfs.

I searched and found MAGICK_THREAD_LIMIT=1 and applied this but not working at all. I tried to apply this using shell command and through .htaccess but not working at all.

I tried to convert the pdf pages to jpg using ghostscript directly, but that's also not working and gives some error (Like no such file or directory).

I'm using this command for IM: convert inp.pdf -background white -alpha remove -colorspace RGB -resize 80% -colorspace sRGB out.jpg
Can anyone please provide me the ghostscript command for this?

Please help me.
Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pdf to jpg conversion not working for some pdfs.

Post by fmw42 »

try

Code: Select all

convert -limit thread 1 inp.pdf -background white -alpha remove -colorspace RGB -resize 80% -colorspace sRGB out.jpg
or

Code: Select all

MAGICK_THREAD_LIMIT=1 convert inp.pdf -background white -alpha remove -colorspace RGB -resize 80% -colorspace sRGB out.jpg
But I doubt this will cause your CPU usage to go way up with or without 1 thread.

Also please always provide your IM version and platform when posting questions to this forum, since syntax may differ and there could be bugs on old systems.

With PDF files, your command should change the colorspace first before reading the PDF and a few other changes.

Code: Select all

convert -colorspace sRGB inp.pdf  -background white -alpha background -alpha remove -resize 80% out.jpg
or

Code: Select all

convert -colorspace RGB inp.pdf  -background white -alpha background -alpha remove -resize 80% out.jpg
Depending upon how old your IM version is. Very old versions of IM had RGB and sRGB swapped in names. For old version of IM use RGB and for newer versions use sRGB. This is why it is important to identify your IM version.

Depending upon how old your IM version is, -alpha xxx may not work. I know that Godaddy uses very old versions of IM. Or atleast it is for my web site, which is 6.2.8 or there about. Perhaps they have a more current version. But the current version of IM is 6.9.8.10, so Godaddy was about 700 versions old.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Pdf to jpg conversion not working for some pdfs.

Post by snibgo »

Also, what is your version of Ghostscript? If old, perhaps it should be updated.

On my Windows system, adding "-verbose" before the PDF tells me the GS command that is issued.

I suspect GS ignores MAGICK_THREAD_LIMIT.
snibgo's IM pages: im.snibgo.com
diligentG
Posts: 5
Joined: 2017-06-20T06:56:52-07:00
Authentication code: 1151

Re: Pdf to jpg conversion not working for some pdfs.

Post by diligentG »

Hi,

Thanks for the your help, it worked for the PDF filed which were not able to extract into images.
I used the mixed command i. e.

Code: Select all

convert  -limit thread 1 -colorspace RGB "input.pdf" -background white -alpha deactivate -resize 80% -colorspace sRGB -scene 1 "output.jpg" 
Thanks a lot again.

But there is a PDF file of size 17.6 mb, which I'm still having issues with, when I try to extract each pages of this PDF into jpg this gives the following error:
warning: ignoring invalid option raw
convert: Postscript delegate failed `input.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/664.
convert: missing an image filename `output.jpg' @ error/convert.c/ConvertImageCommand/3015.
And please help me with a global solution for this kind of errors because I'll have so many different PDF files with different sizes and content.

And sorry for earlier that I didn't provide my IM and GS versions, those are:
IM:
Version: ImageMagick 6.7.2-7 2016-06-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

GS:
GPL Ghostscript 8.70 (2009-07-31)
Copyright (C) 2009 Artifex Software, Inc. All rights reserved.
Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pdf to jpg conversion not working for some pdfs.

Post by fmw42 »

Your ImageMagick version is over 200 versions old. GS is also old. Currently it is about 9.21. Your errors may be due to a too old version of GS or even ImageMagick. I suggest you upgrade.
diligentG
Posts: 5
Joined: 2017-06-20T06:56:52-07:00
Authentication code: 1151

Re: Pdf to jpg conversion not working for some pdfs.

Post by diligentG »

Thanks!
I though it too but can I upgrade it with shared hosting in godaddy ?
Because I don't have root access in my server and they don't know anything about ImageMagick.

So can you please guide me how can I upgrade my IM in shared hosting ?

Thanks again
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pdf to jpg conversion not working for some pdfs.

Post by fmw42 »

I am not an expert on doing that. I can only suggest that you ask Goddady to help you install a copy in your personal directory.

Other than that, I would suggest you install ImageMagick on your own computer and test the same PDF files to see if an upgrade to a current version of ImageMagick and/or Ghostscript would help.

If you have one troublesome PDF file, you can post it to some free hosting service that will not change your PDF to some other format and put the URL here. Then we can test your PDF on a current version of ImageMagick. One place to post is dropbox.com and make the file shareable.
diligentG
Posts: 5
Joined: 2017-06-20T06:56:52-07:00
Authentication code: 1151

Re: Pdf to jpg conversion not working for some pdfs.

Post by diligentG »

Hi,
I upgraded the IM to version 6.9.8, but still I'm getting this error:

Code: Select all

warning: ignoring invalid option raw
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72'  '-sOutputFile=/tmp/magick-315518yWqWcWJON3Z%d' '-f/tmp/magick-31551G0tknvd78bpH' '-f/tmp/magick-31551Hm8ltLUEEHKo'' (-1) @ error/delegate.c/ExternalDelegateCommand/462.
convert: no images defined `/public_html/dev/assets/images/catalogs/12/cbz-img.jpg' @ error/convert.c/ConvertImageCommand/3258.
SO can anyone please help me with that?
Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Pdf to jpg conversion not working for some pdfs.

Post by snibgo »

I don't know where "warning: ignoring invalid option raw" is coming from.

If you are still on Ghostscript 8.70, I suggest you upgrade it.
snibgo's IM pages: im.snibgo.com
diligentG
Posts: 5
Joined: 2017-06-20T06:56:52-07:00
Authentication code: 1151

Re: Pdf to jpg conversion not working for some pdfs.

Post by diligentG »

Yes I upgraded my ghostscript too to latest version (9.21), but not working.

Can anyone please give me command for ghostscript directly from the command which I'm using for IM:

Code: Select all

convert  -limit thread 1 -colorspace RGB "input.pdf" -background white -alpha deactivate -resize 80% -colorspace sRGB -scene 1 "output.jpg" 
I would like try that too. As this is only option I've left.

Thanks
Roysden
Posts: 1
Joined: 2017-08-01T04:49:57-07:00
Authentication code: 1151

Re: Pdf to jpg conversion not working for some pdfs.

Post by Roysden »

diligeentG wrote: 2017-06-23T06:02:22-07:00 Yes I upgraded my ghostscript too to latest version (9.21), but not working.

Can anyone please give me command for the appetite suppressants blog ghostscript directly from the command which I'm using for IM:
Hi Diligent, did you find out what the correct command was? If so please share!
Last edited by Roysden on 2018-05-22T02:05:05-07:00, edited 3 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pdf to jpg conversion not working for some pdfs.

Post by fmw42 »

diligentG wrote: 2017-06-23T06:02:22-07:00 Yes I upgraded my ghostscript too to latest version (9.21), but not working.

Can anyone please give me command for ghostscript directly from the command which I'm using for IM:

Code: Select all

convert  -limit thread 1 -colorspace RGB "input.pdf" -background white -alpha deactivate -resize 80% -colorspace sRGB -scene 1 "output.jpg" 
I would like try that too. As this is only option I've left.

Thanks
I believe if you add -verbose after convert, the command will return the Ghostscript command that was used.

If you just want the first page processed, then try.

Code: Select all

convert -verbose  -limit thread 1 -colorspace RGB "input.pdf[0]" -background white -flatten -alpha deactivate -resize 80% -colorspace sRGB "output.jpg" 
I have added -flatten to your command, since it looks like you want a transparent PDF made white. The use of -background white does nothing by itself, since it is a setting. It needs an operator such as -flatten to act on that setting.
Post Reply