Convert a PDF file into a single Image using ImageMagick

Don't know when you might feel the necessity to convert a pdf into a .jpg or a .png file , but in case you have to, then ImageMagick will make this job really easy for you. ImageMagick is a great opensource command line utility for image manipulation.

Since, we are dealing with image conversion we will use the "convert" script, provided by ImageMagick.

[shredder12]$ convert file.pdf image.png

If the pdf file(file.pdf) has only one page then a single image.png file will be formed. In case of multiple pages, same number of image-[n].png files will be produced. For example, a three page pdf will result into three image files - image-0.png, image-1.png and image-2.png.

If you want to combine/stitch all these images together to form a single one, something similar to taking a snapshot of the whole pdf, then just run the following command.

[shredder12]$ convert image-* -append single_image.png

This will result in a single image file.

6 Comments

Richard Querin (not verified)
June 18th, 2010 07:52 am
Good tip. I use this fairly regularly. Another important option is to use the -density switch when doing the conversion to control the resolution of the resulting image. I deal with drawings provided in pdf form with dimensions and fairly small text notes etc. These are usually in a vector form in the pdf. If I want to have this as a usable png file to touch up or modify in the Gimp say, I need it fairly high res. So I might do: convert -density 300 input.pdf output.png This will create a png file using 300 dots per inch to convert the vector pdf file into the bitmap format. So you'll end up with a significantly larger image file than if you used say 100.
June 18th, 2010 11:51 am

Hi Richard, thanks for this great advice. I haven't dealt with such conversions often so am not aware of various options convert provides, but this will certainly be helpful to a lot of users with similar issues.

Micah Cochran (not verified)
June 18th, 2010 07:46 pm
I also use this on a regular basis. I am usually take high resolution PDFs (ranging from letter to ARCH E) and scaling them down to fit on a browser. I use unsharp mask to bring out thin lines on the drawing so I'd add the option, -unsharp flag. The thing that keeps me coming back is that I can specify the resulting image size by using -resize WIDTHxHEIGHT. The nice thing is that one can be omitted and it will automatically calculate the other dimension. If I am converting a tall image for a web browser, I will typically use -resize x750 I also ghostscript (IM is a heck of a lot simpler with the command line). Recently, I discovered that PDFCreator (windows) can all do the conversion to a particular DPI. Also, GIMP can do the conversion using both DPI and resize, but I have yet to compare the results with IM. The only qualm I have with ImageMagick is in converting PDF file it can be little slow. Now, I only wish there was a VectorMagick for a toolkit for PDF, SVG, AI, EMF, etc.
Julia (not verified)
September 15th, 2010 08:18 pm
Is there a Python version of ImageMagick? I know there is one for PERL, but I mostly code in Python... Tried asking the dudes in StackOverflow, but no response so far.
Micah Cochran (not verified)
September 17th, 2010 04:49 pm
Julia, ImageMagick is written in C and has interfaces for many languages on the ImageMagick homepage including Python. There are two interfaces for Python.
Bogi Dewd (not verified)
September 23rd, 2010 07:51 pm
Why not just combine it into one command? You get one file whether the pdf is a single page or multiple pages... convert file.pdf -append image.png My 2 cents...

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.