In this article you will learn to how to convert a PDF file to Image in Linux command line interface. Pdftoppm converts Portable Document Format (PDF) files to the color image files like PNG, JPG etc. Pdftoppm reads the PDF file and creates one PPM (image) file for each page.
Before beginning this tutorial, you must have to install below package on your system. Use one of the following commands to install poppler package
# On Ubuntu/Debian & Linux Mint
sudo apt install poppler-utils# On CentOS/RHEL & Fedora
sudo dnf install poppler-utils# On Arch Linux
sudo pacman -S poppler
As you have installed required packages on your system. Let’s start converting pdf file to images via Linux command line.
A basic syntax to convert a pdf file to image looks like:
pdftoppm [options] PDF-file image_name
- options – Define options like image format
- PDF-file – Input PDF file
- image_name – Set a name for output images
1. Convert PDF to Image (all pages)
I have downloaded a sample pdf file with 5 pages. Then used pdftoppm command to convert PDF to images. It will create a separate image for each pdf page.
pdftoppm -jpeg Sample.pdf output_file
You can also change
-png to create png files.
Once the file converted, use
ls -l command to list all files in current directory. Here you will see all the images generated from pdf file.
2. Convert PDF to Image (Specific Pages)
Instead of creating images of all pages, you can also convert specific pages only.
pdftoppm -jpeg -f 2 -l 4 Sample.pdf output_file
-f define the first page to start and
-l defines the last page to convert.
As per the above command, it will create images of pages 2 to 4 only.
3. Specify PDF Password
For the password protected pdf files, specify the user password using
-upw command line option.
pdftoppm -jpeg −upw user_password_here Sample.pdf output_file
In this tutorial, you have learned to convert PDF to images using Linux command line.
pdftoppm --help command to get more help about this command.