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.
$ 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:
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:
To convert the first page of pdf file into jpg image:
To convert multiple pdf files to jpg format in batch mode:
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.
File Area Memory Map Disk Thread Time ------------------------------------------------------ 768 1.054GB 753.9MiB 1.9632GiB 18.446744EB 1 unlimited
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.
$ 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.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to use Mutt email client with encrypted passwords - December 1, 2015
- How to back up a WordPress website to remote cloud storage from the Linux command line - November 24, 2015
- How to access Dropbox from the command line in Linux - November 22, 2015