How to convert pdf files to jpg format on Linux

While PDF (short for "Portable Document Format") is a widely used document format supported by a variety of applications on multiple platforms, you may want to convert pdf files to jpg format for several reasons. For example, you may want to embed a pdf file into PowerPoint or OpenOffice Impress presentations, in which case jpg/jpeg images will be easier to work with. Converting a pdf file into jpg also makes it unnecessary to load a separate plugin or external application for web browsers to render it. If you are looking to convert pdf files to jpg/jpeg format on Linux, the following guide will help.

The easiest one-shot solution to convert pdf to jpg/jpeg is using ImageMagick.

$ sudo apt-get install imagemagick
$ convert input.pdf output.jpg

Note that if input.pdf is a multi-page pdf file, the above command will produce as many jpg files as there are pages in the pdf file (e.g., output-0.jpg, output-1.jpg, output-2.jpg, etc).

Other advanced usages of convert command are as follows.

To convert pdf file to jpg image with JPEG compression level set to 100:

$ convert -quality 100 input.pdf output.jpg

The "-quality" option in the above specifies image compression level. For JPG images, an allowed compression level ranges from 1 (lowest quality and highest compression) to 100 (best quality and lowest compression).

To convert pdf file to jpg image with width 500px:

$ convert -density 500 input.pdf output.jpg

To convert the first page of pdf file into jpg image:

$ convert input.pdf[0] output.jpg

To convert multiple pdf files to jpg format in batch mode:

$ for i in `ls *.pdf`; do convert "$i" "$i".jpg; done

If you think that converting pdf with convert utility takes too much memory to be completed properly, you can check the available resource on your system, and limit the resource usage of convert command accordingly.

$ identify -list resource
File         Area       Memory          Map         Disk    Thread         Time
 768      1.054GB     753.9MiB    1.9632GiB  18.446744EB         1    unlimited
$ convert -limit area 64MiB -limit memory 64MiB input.pdf output.jpg

ImageMagic/convert in the above so far relies on Ghostscript to interpret PDF files. You can actually Ghostscript directly to convert pdf files to jpg format as follows.

$ sudo apt-get install ghostscript
$ gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=5 -sOutputFile=output%d.jpg -dJPEGQ=100 -r500 -q intput.pdf -c quit

The above command will generate a series of output files (image1.jpg, image2.jpg,..., image5.jpg) for the first 5 pages of input pdf file. The JPEG compression level is set to 100, and output image resolution is set to 500px (width).

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to convert pdf files to jpg format on Linux

  1. The -density flag isn't for width, it's for the DPI, so the above example would produce a JPG with a density of 500dpi. What you really want to use is the -resize option. ie: "$ convert -resize 500 input.pdf output.jpg" outputs a jpg of 500px wide with a proportional height. .

Leave a comment

Your email address will not be published. Required fields are marked *