The Wayback Machine - https://web.archive.org/web/20240807090301/https://www.geeksforgeeks.org/how-to-convert-pdf-to-image-in-linux-command-line/
Open In App

How to Convert PDF to Image in Linux Command Line?

Last Updated : 25 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Pdftoppm is a tool that converts PDF document files into .PNG format and many other formats. We can use this tool on Linux to convert the PDF into images. It also provides the features like the cropping image, set resolution, and scale, and many more. Now let’s see how to install the pdftoppm

Installation of pdftoppm:

To install the pdftoppm, we need to install the poppler-utils package on the Linux system because the pdftoppm comes with the poppler package. To install the poppler-utils use the following commands:

To install the poppler-utils on debian based system like Ubuntu and kali Linux use the following command:

sudo apt install poppler-utils 

To install the poppler-utils on the RHEL/CentOS & Fedora use the following command:

sudo dnf install poppler-utils  

To install the poppler-utils  on Arch-based OS uses the following command:

sudo pacman -S poppler     

How to Convert PDF to Image in Linux Command Line

Now we have installed the pdftoppm on the system. Now let’s see how to use the pdftoppm

Using the pdftoppm

Now let’s convert the pdf into the images. To convert complete pdf into the images the following is the syntax :

pdftoppm -<image_format> <pdf_filename <image_filenane>

Here in the place of image_format place the format of the image like png  with – and in place of pdf_filename mention the name of pdf and in place of image_filename mention the output filename.

Here is one example of the above command:

pdftoppm -png gfg.pdf  gfg_d

How to Convert PDF to Image in Linux Command Line

We can see in the above image that all pages have the name ends with the page number. This will be automatically done by the pdftoppm.

Range of PDF pages into the images:

Now let’s see how to convert the range of the PDF pages into the images. To do that the following is the syntax of the command:

pdftoppm -<image_format> -f N -l N <pdf_filename> <image_name>

Here, -f denote the first and N denote the page number, and -l denotes the last and N to the page number. Here is one example of the above command:

 pdftoppm -png -f 5 -l 10 gfg.pdf  gfg_d

How to Convert PDF to Image in Linux Command Line

We can see in the above image output the specified section of PDF is converted into the .pdf format image.

Converting a Single page into the image

To convert the specific one page into the image we can modify the above command like we will keep the both -f and -l number same as of the page to be converted into the image like

pdftoppm -png -f 3 -l 3 gfg.pdf  gfg_d

To convert the first page into the image we can modify the above command as follows:

pdftoppm -png -f 1 -l 1 pdf_name.pdf image_name.png

Then the only first page will be converted into an image like:

How to Convert PDF to Image in Linux Command Line

Monochrome and Grayscale image output:

We can generate the images of pdf in grayscale and monochrome by using just simple command:

For grayscale image:

pdftoppm -png -gray pdf_name.pdf image_name         

For monochrome image:

pdftoppm -png -mono pdf_name.pdf image_name 

Here is an example of the above command:

How to Convert PDF to Image in Linux Command Line

Adjust the DPI Quality of the output image

Now let’s see how to adjust the DPI Quality of the output image. By default, the  DPI quality of the output image is 150, but we can change it. To change the DPI quality we can use the -rx option to specify the X resolution and -ry option to specify the Y resolution of DPI.

pdftoppm -png -rx 350 -ry 350 

To know more about the pdftoppm you can see the man page or use the help command 

pdftoppm --help 

or

man pdftoppm

How to Convert PDF to Image in Linux Command Line



Similar Reads

How to Compare Files Line by Line in Linux | diff Command
In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process is the diff command. In this article, we will explo
9 min read
How to Convert DOS line endings to Linux line endings using Vim
DOS and Unix/Linux file formats differ slightly such that the ASCII characters used at the line endings are different. Unix file format uses an LF character to end a line, LF stands for LineFeed, which means moving the cursor down. Unix-based systems and Mac OS X &amp; later use this format. While the DOS file format uses a CR character before the
2 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
How to Install NuGet from Command Line on Linux?
NuGet is the package manager for the .NET framework. It's very much useful for developers as developers can create, publish and consume packages. The package format of NuGet consists of a single ZIP file with the extension of .nupkg and which is the DLL compiled code like the package’s version number. A NuGet package manager is a cross-platformed m
2 min read
How to Download YouTube Videos in Linux Command Line?
The videos can be downloaded from the online source through the Linux terminal using the youtube-dl tool. youtube-dl is a Python-based small command-line tool that makes it possible to download the videos from Youtube, Facebook, Dailymotion, and few more similar sites. It is written in PyGTK and requires Python interpreter to run this program, it’s
2 min read
Connecting to the Internet Using Command Line in Linux
Many of the times you may use a Linux system that does not have a GUI after install and it needs an internet connection to set up a desktop environment, also you may use Linux servers without a GUI and you need to connect over a wireless network using the command line. Below you will see Steps to connect to a wireless network using the command line
3 min read
Kali Linux - Command Line Essentials
Command-line plays a vital role while working with Kali Linux as most of its tools don't have a Graphical User Interface and if you are performing ethical hacking or penetration testing then most of the time you will have to work with command Line Interface itself. While executing a command in Kali Linux we enter a command on the terminal emulator
3 min read
Deepl - Command Line Language Translator Tool for Linux
Deepl is the best language translator command-line tool that detects the language of input text and translates it into the desired language using advanced machine learning and neural networking algorithms. It is open source and powered by a German tech Company under the MIT license. It supports the following languages English (EN)Italian (IT)Spanis
3 min read
Command-Line Tools and Utilities For Network Management in Linux
If you are thinking of becoming a system administrator, or you are already a system admin, then this article is for you. As a system admin, your daily routine will include configuring, maintaining, troubleshooting, monitoring, securing networks, and managing servers within data centers. Network configuration and troubleshooting are some important t
8 min read
Article Tags :
three90RightbarBannerImg