Hello, friends. In this short but useful post, you will learn how to convert PDF to images on Linux. While this may seem complicated at first glance, the reality is that it is not. So let’s get to it.
The process of converting PDF to images is simple because we will do it using the
pdftoppm tool that is run through the terminal.
According to the
pdftoppm man page:
Pdftoppm converts Portable Document Format (PDF) files to color image files in Portable Pixmap (PPM) format, grayscale image files in Portable Graymap (PGM) format, or monochrome image files in Portable Bitmap (PBM) format.
However, it can also be used to generate PNG or JPEG files.
This command is generally not installed by default on all Linux distributions. So we have to install it before using it.
So, for Debian and Ubuntu-based distributions, install the tool with the following command
sudo apt install poppler-utils
For CentOS, AlmaLinux, RockyLinux, and Fedora, you can install it using:
sudo dnf install poppler-utils
And for Arch Linux based distributions, you can run it with:
sudo pacman -S poppler
The use of the command is quite simple and has the following syntax:
pdftoppm [options] [PDF-FILE] [Output] [PDF-FILE] [PDF-FILE] [Output]
Also, like any command, you have options that modify the behavior of the command. Some of these options are:
- -f number: Specifies the first page to convert
- -l number: Specifies the last page to convert.
- -r number: Specifies the X and Y resolution, in DPI. The default is 150 DPI.
- -rx number: Specifies the X resolution, in DPI. The default is 150 DPI.
- -ry number: Specifies the Y resolution, in DPI. The default is 150 DPI.
- -scale-to number: Scales each page to fit in scale-to*scale-to pixel box.
- -scale-to-x number: Scales each page horizontally to fit in scale-to-x pixels.
- -scale-to-y number: Scales each page vertically to fit in scale-to-y pixels.
- -x number: Specifies the x-coordinate of the crop area top left corner
- -y number: Specifies the y-coordinate of the crop area top left corner
For this post, I have a PDF called
sample.pdf with a large number of pages.
If you want a JPEG file to be generated for each of the pages, you can use the following command:
pdftoppm -jpeg sample.pdf exmple.jpeg
In this case, an image will be generated for each page and in this screenshot, you can see it better.
Also, you can define a range of pages to generate the images with the options
-l which define the first and the last page. For example:
pdftoppm -jpeg -f 2 -l 4 sample.pdf file.jpeg
In this case, only images of pages 2, 3, and 4 are generated.
As you can see the process is very simple and useful.