56

I have PDFs that I need to convert to images. I have installed Imagemagick. I have a PDF named a.pdf that I can open (it is not corrupt) in the folder C:\Convert\

From the command line I am trying

C:\Convert>convert a.pdf a.jpg

And I am getting the error.

convert.exe: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -
dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEV
ICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dUseCIEColor
"-sOutputFile=C:/Users/MNALDO~1.COR/AppData/Local/Temp/magick-3704HYGOqqIK5rhI%d
" "-fC:/Users//MNALDO~1.COR/AppData/Local/Temp/magick-3704vK6aHo7Ju9WO" "-fC:/Use
rs//MNALDO~1.COR/AppData/Local/Temp/magick-3704GQSF9kK8WAw6"' (The system cannot
find the file specified.
) @ error/delegate.c/ExternalDelegateCommand/480.
convert.exe: PDFDelegateFailed `The system cannot find the file specified.
' @ error/pdf.c/ReadPDFImage/797.
convert.exe: no images defined `a.jpg' @ error/convert.c/ConvertImageCommand/323
0.

UPDATE:
After the SO community helped me solve this issue I put together a little tool to batch convert images. Hope it helps somebody. https://github.com/MattDolan/ImageConverter

MatthewD
  • 6,361
  • 5
  • 18
  • 41
  • 2
    You need to install Ghostscript to rasterize vector files (like PDF, EPS, PS, etc.) with Imagemagick. – Crontab Sep 08 '15 at 19:54
  • Is the imagemagick convert command looking for that to be installed or is that an alternative software to use for doing this conversion? – MatthewD Sep 08 '15 at 19:56
  • 1
    Both. Imagemagick requires it for vector file rasterization, but it basically shells out to Ghostscript to do it. In fact, the whole Ghostscript command line is listed in your question (starting at "gswin32c.exe" and ending just before "(The system cannot".) – Crontab Sep 08 '15 at 19:59

5 Answers5

71

You need to install Ghostscript in order to rasterize vector files (PDF, EPS, PS, etc.) with ImageMagick. IM will shell out to Ghostscript when doing these manipulations (you can see it if you use the -verbose tag in your IM invocation). You could also use Ghostscript by itself to rasterize vector files.

Crontab
  • 8,996
  • 1
  • 25
  • 31
  • 1
    I installed ghostscript and it worked perfectly. Also found here an example of all the options for the convert command. http://stackoverflow.com/questions/6605006/convert-pdf-to-image-with-high-resolution – MatthewD Sep 08 '15 at 20:10
  • 2
    Is there a way to install Ghostscript portably? I have a portable installation of ImageMagick on a flash drive and I'd like to also have a portable way of converting PDFs to JPGs. – 9a3eedi Mar 09 '17 at 09:27
  • On Windows it is simply a .dll file, so it should be possible. Just, make sure your file is present in the $PATH, and make sure the file is named `gs.exe` and not something like `gswin64.exe` – John Apr 19 '21 at 10:59
38

Since you actually have to install Ghostscript to do this, why not drop ImageMagick all-together? It just forwards the command to Ghostscript anyway, not adding any value, just taking way longer to process (and loading everything into RAM while its at it).

Install GhostScript and run the command:

gswin64c.exe -dNOPAUSE -sDEVICE=jpeg -r200 -dJPEGQ=60 -sOutputFile=foo-%03d.jpg foo.pdf -dBATCH

This is identical and faster than running:

convert -quality 60 -density 200 foo.pdf foo-%03d.jpg
Wolf5
  • 14,590
  • 11
  • 57
  • 55
  • Note that Ghostscript is licensed under AGPL and not LGPL and the Ghostscript company (Artifex Inc) has lawyers which consider invoking Ghostscript via the command-line to constitute a derivative work... consult your company's legal team before using Ghostscript in any product or service! – Dai Sep 09 '20 at 08:24
3

It's in the docs now. https://github.com/dlemstra/Magick.NET/blob/master/Documentation/ConvertPDF.md

You need to install the latest version of GhostScript before you can convert a pdf using Magick.NET.

Make sure you only install the version of GhostScript with the same platform. If you use the 64-bit version of Magick.NET you should also install the 64-bit version of Ghostscript. You can use the 32-bit version together with the 64-version but you will get a better performance if you keep the platforms the same.

Here is a wrapper: https://archive.codeplex.com/?p=ghostscriptnet

addohm
  • 1,593
  • 2
  • 9
  • 28
0

Install GhostScript GNU Affero General Public License from here.

CRBelhekar
  • 91
  • 1
  • 4
0

I found that I had installed GhostScript, but GhostScript was not able to execute because it needed additional libraries. By typing "gs" on a command line, I was able to see what libraries were missing.