Converting PDF to JPG via ImageMagick   no comments

Posted at 8:20 pm in Linux

Ever recieved a comic book or magazine pdf file and wondered if you can extract the JPG images off it? Well there are a number of commercial and free/shareware tools for windows if you are good at googling. But what if you’re using Linux? Or you have a bunch of PDF files and you want to convert all of them in one go?

Simple, use ImageMagick’s convert tool.

Let’s say you have a PDF file named FunnyComics.pdf and you want to extract the pages into separate JPG files.

convert FunnyComics.pdf FunnyComics%d.jpg

will convert FunnyComics.pdf into separate jpg files named FunnyComics0.jpg, FunnyComics1.jpg, FunnyComics2.jpg… and so on until it reaches the last page of FunnyComics.pdf. The ‘%d‘ appended to the end of the output means you want to number the converted files. Quite simple isn’t it?

Now let’s say you want a larger size jpg than the one in our previous example. Just add the ‘-geometry widthxheight‘ commandline option.

convert -geometry 1024x768 FunnyComics.pdf FunnyComics%d.jpg

will result in files with a width of 1024 pixels OR 768 pixel height, whichever is the largest number. ImageMagick will always assume you want a 1:1 aspect ratio from the original source of the image.

Before we wrap it up I’d like to introduce you to another option to convert which will give us control over the quality of the image produced. We’ll use the ‘-quality nn‘ option for that.

convert -geometry 1280x1024 -quality 85 FunnyComics.pdf FunnyComics%d.jpg

will give us images of 85% quality. 85% is quite the norm for most jpegs. If you go higher than that it will result in a bigger size of the file but you can’t really distinguish (with your Mark 1 eyeball) the minute differences between an 85% and a 100% jpeg file.

This trick will work both in regular Unixes (linux and the like) and on Windows via Cygwin’s version of ImageMagick.

Written by admin on March 9th, 2008

Tagged with , , , , ,

Leave a Reply