ImageMagick: PDF to JPG Conversion Error

Problem

I tried to convert a PDF file to a JPG image using convert.exe from ImageMagick and got the following error:

$ convert Foobar.pdf Foobar.jpg
convert: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraph
icsAlphaBits=4 "-r72x72"  "-sOutputFile=C:/Users/Joe/AppData/Local/Temp/magick-p1m2jxT1" "-fC:/Users/Joe/AppData/Local/Temp/magick-tf9Qz_d_" "-fC:/Users/Joe/AppData/Local/Temp/magick-sa
5AGTv3" @ error/utility.c/SystemCommand/2093.
convert: Postscript delegate failed `Foobar.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/645.
convert: missing an image filename `Foobar.jpg' @ error/convert.c/ConvertImageCommand/2970.

Solution

It looks like the input or output filenames are missing or have some problem. Look closer and it is an error caused by gswin32c.exe. ImageMagick uses gswin32c.exe from the Ghostscript package to convert PDF files. So, to fix this error make sure that:

  1. Ghostscript package is installed.
  2. The directory containing gswin32c.exe is in the PATH environment variable.

ImageMagick: Missing DLL

Running 64-bit convert.exe from the installation of ImageMagick-6.6.3-3-Q16-windows-x64-dll.exe gives this error:

The program can’t start because CORE_RL_wand_.dll is missing from your computer. Try reinstalling the program to fix this problem.

The packagers have forgotten this DLL. The solution is to install the statically linked ImageMagick-6.6.3-4-Q16-windows-x64-static.exe or try a x64-dll.exe installer of an older version.

ImageMagick: JPEG-PDF Conversion Segmentation Fault

As I have blogged earlier, I use the ImageMagick convert program to convert my JPG scans to PDF files. This command which works fine on Windows ends up in a segmentation fault on Ubuntu:

$ convert scans-*.jpeg fooBar.pdf
Segmentation fault

There is a workaround for this error by using a compression method that is different (JPEG) from the default method (Zip). But, the real longterm solution seems to be a switch to GraphicsMagick.

What is this GraphicsMagick you say? It is a fork of the ImageMagick code aimed at efficiency, performance and stability. It pains me to see projects in the opensource world forking like this even today. GraphicsMagick is available on Ubuntu repositories and can be installed using the Synaptic Package Manager by looking for the graphicsmagick package. Using GraphicsMagick for the JPEG-PDF conversion worked fine without any errors. GraphicsMagick commands and parameters are the same as ImageMagick, except with a prefix of gm:

$ gm convert scans-*.jpeg fooBar.pdf

IrfanView: Batch Operations on Images

The ImageMagick basket of command-line tools can be used to do almost anything to a set of image files. But, sometimes figuring out the options to pass the tool can be too much work for a small batch operation. IrfanView, (still) the best image viewer on Windows is the next best tool for such quick operations.

  • Choose FileBatch Conversion / Rename to apply batch operations.
  • Rename files. All sorts of numbering can be added as prefix or suffix to the files.
  • Crop, resize, rotate, flip or almost anything imaginable can be applied on the files.

ImageMagick: Convert images to PDF document

The convert command-line tool from ImageMagick is the easiest way I know to convert a bunch of images into a single PDF document. It is as easy as:

convert *.jpg paper.pdf

(Make sure the ImageMagick installation path is in your %PATH% environment variable for this to work from any directory.)

I typically use this to convert the scans of old CS papers. Even today there is a surprisingly large amount of old CS papers that are not available online in a digital format. The only option is to head down to the library, get hold of the journal and either photocopy or scan the pages. I always prefer to scan in the paper as JPG images, then straighten and edit the images a bit in Picasa and then convert it into a PDF document.