Convert a PDF Document to Images in the Linux Terminal

We have already discussed earlier the process of converting image files into a PDF document. The opposite is also possible, that is, you can also convert any number of pages inside a PDF document into a series of Images. This trick can be used to edit a PDF file if you first convert it to image and then edit it as per your needs and then convert it back to PDF.

With pdftoppm, you can convert a PDF document to image really easily in the terminal, and you can also specify the resolution, scale and even crop the image if you want to.

Also read: pdfgrep – Search for text inside a PDF document

Install pdftoppm

Open a Terminal and type the following command, depending upon your distribution :

# On Debian and Ubuntu based distributions
sudo apt update && sudo apt install poppler-utils

# On Fedora Workstation
sudo dnf install poppler-utils

# On Arch Linux
sudo pacman  -S poppler
Poppler Utils Is Already Installed On My Fedora
poppler-utils is already installed on my Fedora

Convert a PDF document to Image

The conversion procedure is really simple, you just have to type the pdftoppm command like this :

pdftoppm -image_format pdf_name image_name
Converting A PDF Document To Image
Converting A PDF Document To Image

Here, -image format flag will set the format of the image to your preference (such as JPEG, PNG etc.)

Specify a range of pages to convert

You can use the -f and -l command options to specify the first and last pages of the document you want to convert to image. Let’s see an example below :

pdftoppm -png -f 2 -l 5 Lockpick_Guide.pdf Picture
Converting To Images In A Specified Range
Converting to images in a specified range

As we can see, only 3 images have been produced as we have specified using the command options.

Adjust the quality of the output

By default, pdftoppm produces images with a DPI of 150, but we can adjust this parameter by using the -rx and -ry options which will define the X resolution and Y resolution respectively. For example, let’s try producing images with 200 DPI, type :

pdftoppm -png -rx 200 -ry 200 pdf_name.pdf image_name
Specifying The DPI While Converting PDF To Image
Specifying The DPI While Converting PDF To Image

Summary

That’s about it, I hope you have learned something related to this tool and find practical use of this knowledge. Let me know in the comments if you have any queries related to this tool.