Linux: Convert a PDF File To an Image

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 29 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
29 comments… add one
  • igor Jan 16, 2009 @ 10:05

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

  • ob1y2k Jan 16, 2009 @ 11:13

    hm, life saving command ^_^

  • divide_by_zero Jan 16, 2009 @ 13:28

    Doesn’t the Gimp open PDF files?

  • Laurent GRÉGOIRE Mar 9, 2009 @ 21:13

    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.

    • linuxkasten Aug 1, 2011 @ 13:00

      thank you very much!

      • Jose_X Oct 18, 2011 @ 19:59

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

    • Robinson Nov 26, 2011 @ 4:40

      buenisimo…! =D Gracias

    • Marcus Wanner Dec 6, 2011 @ 4:44

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

    • Perdu Mar 10, 2014 @ 17:39

      Thanks a lot

    • Andrey Aug 31, 2014 @ 11:13

      thanks for useful parameter!

    • Jan M. Nov 13, 2014 @ 8:14

      Great, thanks.

  • Martin Jul 27, 2009 @ 19:44

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

  • tsyma Oct 1, 2009 @ 16:08

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

  • Patrick EB Jun 21, 2010 @ 3:06

    Sometimes life is so easy :)

    Convert pdf to png and back again with such ease.

    Very nice :))

  • lali May 12, 2011 @ 13:50

    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 ..

  • hans Dec 27, 2011 @ 12:27

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

  • Carl Feb 5, 2012 @ 21:41

    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!

  • Rolando Feb 7, 2012 @ 15:08

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

    • Alastair Feb 10, 2012 @ 11:20

      “convert eagle-strike.pdf eagle-strike.mp3” :P

  • Aripin Feb 10, 2012 @ 6:27

    Yes the trial can covrent to any of the formats, did you download the Standard trial or Pro?

  • Craig Owen Feb 12, 2012 @ 20:08

    I’m trying to convert a 350 page pdf file (95MB). If I set the density to 72×72 it works perfectly but I can’t read the text. If I set the density to 150×150 it crashes out after page 3. I’m guessing that I’m running out of memory. Is there any way to specifiy the page number to start the conversion from?
    Any help is appreciated

    • Alastair Feb 12, 2012 @ 22:54

      Add -f 1 -l 10 for starting on the first page and ending on the tenth. You might need another tool to split it into smaller chunks first, though.

  • nrivoli May 27, 2012 @ 23:52

    -depth 8 for lower size file

  • Dan Jun 28, 2013 @ 7:27

    im using convert command to a pdf with thai characters in it but when i do, the resulting file does not contain thai characters(it is replaced by empty characters) . Please advise.

  • Sanyogita Mande Nov 7, 2013 @ 9:54

    this “density” option really helps with the convert command :)
    i am glad to get a good quality image post conversion
    Thanks a lot

  • Katherine Dimacale Sep 17, 2014 @ 23:23

    Thanks for this helpful guide. I’ll find it easier to convert my files to an image. Btw, if you want the other way around, you can also use this tool I just discovered it and it’s easy to use. Give it a try

  • chaitanya patel Sep 27, 2015 @ 17:04

    I want to convert 1.jpg, 2.jpg, 3.jpg, … , 20.jpg in a single pdf using a command. The images should be in order. (1.jpg then 2.jpg and so on) I am doing it with convert *.jpg my.pdf .
    but pdf is not ordered as I want. How can I do that ? Please advise.

    • David Oct 31, 2015 @ 16:59

      Reply to C. Patel
      I suspect the files are in alphabetic order instead of number order,
      so 1 10 11 12 2 3 4 5 6 7 8 9 for 1 to 12. Try using two digit numbering
      01 02 03 04 05 06 07 08 09 10 11 12.

      Good luck.

  • serfer2 Sep 27, 2015 @ 18:11

    For modern Debian or Ubuntu based distros like Linux Mint, you can get the “convert” command by installing package:

    “poppler-utils” (for all PDF related tasks).

    With this package, you’ll get:
    * pdfdetach — lists or extracts embedded files (attachments)
    * pdffonts — font analyzer
    * pdfimages — image extractor
    * pdfinfo — document information
    * pdfseparate — page extraction tool
    * pdftocairo — PDF to PNG/JPEG/PDF/PS/EPS/SVG converter using Cairo
    * pdftohtml — PDF to HTML converter
    * pdftoppm — PDF to PPM/PNG/JPEG image converter
    * pdftops — PDF to PostScript (PS) converter
    * pdftotext — text extraction
    * pdfunite — document merging tool

    Enjoy ;-)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum