Portable Document Format (PDF) files are widely used nowadays. Images in any format are still easier to edit and manipulate than PDF files so it is general practice to convert pdf files to images to edit them.
In this article, you will learn different ways to convert PDF files to images.
- Linux-based system
- Terminal access
- A user account with sudo privileges.
Note: The commands in this tutorial are executed on a Linux Mint system. All the methods in the tutorial are valid for any Linux-based system.
Convert PDF to Image Using the Command Line Interface(CLI)
Convert PDF to Image With Pdftoppm Tool
Pdftoppm command-line tool comes in the popper-utils package. To install and use pdftoppm, first install the popper-util package.
sudo apt-get install poppler-utils
Following is the basic syntax of the pdftoppm command.
pdftoppm -<image_format> <pdf_filename> <image_name>
Note: The name of the PDF file used in this tutorial is sample.pdf. You need to insert your filename and image name in the above command.
pdftoppm -png sample.pdf sample
Pdftoppm tool comes with various options. For example, you can target and convert specific pages in your pdf file with the following command.
pdftoppm -png -f 10 -l 15 sample.pdf Sample
-f and -l option specifies the first and last page number. In the output, you can see the converted images reflect the mentioned range.
You can also customize the quality of your converted image with pdftoppm. To customize quality, use -rx and -ry options to change the width and height resolutions.
pdftoppm -png -rx 300 -ry 300 sample.pdf sample
To learn more about the pdftoppm tool and its options, run the following command and read detailed information.
Convert PDF to Image With Imagemagick Tool
Imagemagick is another utility that offers image manipulation functions. It also has programming APIs which makes it highly convenient for use.
You can install the Imagemagick utility with the following command.
sudo apt install imagemagick
Once it is installed, You can convert your pdf files to images with the following command.
convert sample.pdf output_image.jpg
You can see that PDF file conversions are not authorized by policy. If you get this output, go to the Imagemagick policy XML file with the following command.
sudo nano /etc/ImageMagick-6/policy.xml
You will see the following code snippet at the end of the file.
<!-- disable ghostscript format types --> <policy domain="coder" rights="none" pattern="PS" /> <policy domain="coder" rights="none" pattern="PS2" /> <policy domain="coder" rights="none" pattern="PS3" /> <policy domain="coder" rights="none" pattern="EPS" /> <policy domain="coder" rights="none" pattern="PDF" /> <policy domain="coder" rights="none" pattern="XPS" /> Comment it out in the following format. <!-- code -->
Press Ctrl+O and Ctrl+X to finish editing. Run the following command to convert the PDF.
convert sample.pdf output_image.jpg
As you see, the conversion is successful now.
You can refine images by using the -density and -quality options.
convert -density 300 sample.pdf -quality 100 output_image.jpeg
Convert PDF to Image Using the Graphical User Interface(GUI)
Convert PDF to Image With GIMP Application
GNU Image Manipulation Program (GIMP) is an image manipulation software.
To install GIMP, search and install it from the Software Manager.
Navigate and import the PDF file and go to the page you want to convert into an image.
Then export it as desired image format.
In this article, you have learned various ways to convert your PDF files to image format.