Thursday, 30 October 2008

ImageMagick (convert), GhostScript (gswin32), GSview

To put it simple, I was trying (under Windows XP SP2) to convert a .pdf file into a .jpg file, to upload it on my personal blog.

ImageMagick is quite a good tool. I've been using it under Linux (Kubuntu) and Windows at various projects (i.e. at my diploma project, to convert some images into pdf files; at a project done as a homework for a course, called ASDN, at the faculty - my application had to recognize letters from that type of images used for login / create account and I was using neural networks as part of the solution and I used ImageMagick to play a bit with the images before actually running my algorithm etc.)

Since when I worked at my diploma project I used ImageMagick to convert .gif files into .pdf files and it worked, I supposed the opposite would work flawlessly today. Well... no. When I tried to convert a .pdf into a .jpg it gave the following error:

convert: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=C:/DOCUME~1/john/LOCALS~1/Temp/magick-jTzLRJ_C" "-fC:/DOCUME~1/john/LOCALS~1/Temp/magick-TlaNdwxx" "-fC:/DOCUME~1/john/LOCALS~1/Temp/magick-NkbgXR1g".
convert: Postscript delegate failed `myFile.pdf': No such file or directory.
convert: missing an image filename `myFile.jpg'.

^note: I replaced my actual filename with myfile.

One can imagine I was quite surprised when the error showed up in the command line. Ok, hello little error, let's see what upset you...

After searching a bit on the Internet (thank you, Google) I realized the solution was the following:
  • Install GhostScript for Windows:

  • Optional: install GSview for Windows: - well, since I got so far, why not? It could be usefull sometime in the future... I mean, I have no viewer for .ps or .eps files (ok, for .pdf I have a viewer), and I've always wanted a viewer for those 2 file types, in fact it's been my secret desire for about 2 years now but I've never told anyone; ok, I admit it, I was too lazy to search for a .ps viewer and always clicked on the .pdf version of the same file.

  • Run the convert command at the command line (convert is the mighty and powerfull ImageMagick) as I've tried before and get my job done.

Now, wasn't that simple or what?
Why did I get nervous in the first 15 minutes, mmm?

Ok, I admit it, I faced another tiny little problem after that: the default DPI seemed quite small (I drew this conclusion because some elements, i.e. characters and numbers in the .jpg output looked bad), so I had to increase the DPI in the output. This should help you get the job done.

After some attempts, I decided a 350x350 DPI is enough for me; yes the command was something like:

convert -density 350x350 inputFilename.pdf outputFilename.jpg

And yes, it worked.

Hope this helps you. Keep having fun with technology! ;)

No comments: