Linux: Convert a PDF File To an Image

by Vivek Gite on January 16, 2009 · 15 comments

Q. A friend showed me how to extract images from a pdf file using pdfimages utility. But I'd like to convert my PDF file to image file. How do I convert a PDF to an image file using a command line option?

A. You need to use convert command from imagemagick - image manipulation set of programs.

The convert program is a member of the ImageMagick suite of tools. Use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. This is also useful if you do not have PDF reader installed (Gnome and KDE does have in built PDF reader) or required for your webbased project.

Type the following command to convert foo.pdf to foo.png (foo1.png, foo2.png.. etc if you have multiple pages in a pdf file):
$ convert foo.pdf foo.png
You can specify a different file type by changing the file extension of the second file, type:
$ convert foo.pdf foo.jpg

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 15 comments… read them below or add one }

1 igor January 16, 2009

on debian/etch you need ghostscript (package: gs) for this operation.

Reply

2 ob1y2k January 16, 2009

hm, life saving command ^_^

Reply

3 divide_by_zero January 16, 2009

Doesn’t the Gimp open PDF files?

Reply

4 Laurent GRÉGOIRE March 9, 2009

Use “-density ” option for setting precision in points per inch, example:
$ convert -density 300 file.pdf image.png
By default the dpi is 72, which could be too low. Make sure the option is _before_ the filenames though.

Reply

5 linuxkasten August 1, 2011

thank you very much!

Reply

6 Jose_X October 18, 2011

I second that.. especially the part about “_before_ the filenames”

Reply

7 Robinson November 26, 2011

buenisimo…! =D Gracias

Reply

8 Marcus Wanner December 6, 2011

Thank you so much. I had no idea that putting the arguments in a different order would make a difference.

Reply

9 Martin July 27, 2009

Thanks Laurent, that density option was the command I was looking for. Now I can have image output at appropriate quality.

Reply

10 tsyma October 1, 2009

on debian/lenny you need imagemagick(package: imagemagick) for this operation

Reply

11 Patrick EB June 21, 2010

Sometimes life is so easy :)

Convert pdf to png and back again with such ease.

Very nice :))

Reply

12 lali May 12, 2011

i dont know why but this isnt working for me .
i have 2 Gb of free space and what this command does is reduce it to 4 KB .
No output file or anything is generated ..

Reply

13 hans December 27, 2011

Thanks!! It was exactly what I was looking for!

Reply

14 Carl February 5, 2012

Love ImageMagick for it’s neat feature to handle PDF (more or less as-is). Also, big thanks to Laurent for explaining the “-density” switch; which (until now) was the missing point in my latest workflow. Cheers!

Reply

15 Rolando February 7, 2012

i dolwnoad eagle strike audio book and it came up as file so renamed it .mp3 still no work

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 2 + 9 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: