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