If you need to convert a PDF file or multiple PDF files to image file format like JPG or PNG, then you can do so using the Linux Command Line. No need to invest money in expensive software that do the same. Linux has a tool called pdftoppm that does the job for you. In this article, learn how to use pdftoppm to convert PDF files to JPG and do some basic editing.
Before you start using the tool, you need to install it. Pdftoppm is part of poppler/poppler-utils/poppler-tools package.
So go ahead and install the package using the following relevant command:
Converting PDF to Image
To convert a PDF file to image file with pdftoppm, use the following syntax:
Make sure to specify appropriate file names in their respective places. For example, in the following command, we’re changing My_PDF_file document PDF file to My_PDF_file image file in png format:
Converting Range of PDF Pages to Image Files
If you’ve got a long PDF file and want to covert a range of pages, then you can do so using pdftoppm. Use this command for this purpose:
In the above code, N is the first page and -l N is the last page. In real life, this is what it will look like:
Converting Only First Page of PDF Document
If you want to convert only the first PDF page, then here’s the code to execute:
Adjusting DPI Quality when Converting
As already said, you can do some basic editing with pdftoppm tool. And one of them is to adjust DPI quality. By default, the tool converts PDF files to image files while maintaining a DPI of 150. You can change it using the rx and ry number, which specify the X and Y resolution respectively.
In the following code, we change the DPI quality to 300:
To see all the options available, use:
So that was how you can change PDF files to image files using the pdftoppm tool.
Before you start using the tool, you need to install it. Pdftoppm is part of poppler/poppler-utils/poppler-tools package.
So go ahead and install the package using the following relevant command:
Code:
Debian/Ubuntu/Mint - $ sudo apt install poppler-utils
RHEL/CentOS/Fedora - $ sudo dnf install poppler-utils
OpenSUSE - $ sudo zypper install poppler-tools
Arch Linux - $ sudo pacman -S poppler
To convert a PDF file to image file with pdftoppm, use the following syntax:
Code:
$ pdftoppm -<image_format><pdf_filename><image_name>
Code:
$ pdftoppm -png My_PDF_file.pdf My_PDF_file
If you’ve got a long PDF file and want to covert a range of pages, then you can do so using pdftoppm. Use this command for this purpose:
Code:
$ pdftoppm -<image_format> -f N -l N <pdf_filename><image_name>
Code:
$ pdftoppm -png -f 10 -l 15 My_PDF_file.pdf My_PDF_file
If you want to convert only the first PDF page, then here’s the code to execute:
Code:
$ pdftoppm -png -f 1 -l 1 My_PDF_file.pdf My_PDF_file
As already said, you can do some basic editing with pdftoppm tool. And one of them is to adjust DPI quality. By default, the tool converts PDF files to image files while maintaining a DPI of 150. You can change it using the rx and ry number, which specify the X and Y resolution respectively.
In the following code, we change the DPI quality to 300:
Code:
$ pdftoppm -png -rx 300 -ry 300 My_PDF_file.pdf My_PDF_file
Code:
$ pdftoppm --help
$ man pdftoppm