With the pdftoppm utility, you can easily generate image files from a PDF document. And the best part, you can do so by typing a simple command on the terminal. In this article, we will discuss pdftoppm in detail, along with a guide on how to use this tool efficiently.
What Is pdftoppm?
As already mentioned above, pdftoppm is a command-line Linux utility that converts PDF documents into image files. Using pdftoppm, you can configure the format and dimensions of the output images. The tool also allows you to add a color filter such as grayscale to the images.
Pdftoppm is a part of the poppler-utils package on Linux. You won’t find this package preinstalled on any Linux distro, therefore, you’ll have to manually install it.
To install the poppler-utils package on Debian-based distros:
On Arch Linux:
You can install poppler-utils on CentOS and Fedora using either DNF or Yum:
How to Use pdftoppm
The pdftoppm utility has a bunch of options that you can use. The most basic ones being converting a PDF to images, changing the image format, converting only specific pages, and changing the image resolution.
Basic Syntax
The basic syntax of the tool is:
…where imageformat is the file extension that you want the output images to have, document is the path to the PDF file, and imagename is the name of the output image.
Convert Entire PDF to Images
To simply convert a PDF file to images:
The aforementioned command will convert the pages of the document into images. In case the document has multiple pages, pdftoppm will append numbers to the output file name, e.g. output-images-1 and output-images-2.
You can also change the character separator between the output name and the extension with the -sep flag. For example, to use Question Mark (?) as the separator:
Change the Image Extension
To change the format of the output files, change the file extension in the command. To convert the document into JPEG files:
Pdftoppm supports the following output formats:
PNG JPEG JPEGCMYK JPEGOPT TIFF
If you do not specify a format, the tool generates the images with the PPM extension by default.
Convert a Range of Pages to Images
If you want to convert only a specific range of pages in the document, use the -f and -l flags. The -f and -l stands for first and last respectively.
The above command will only convert the pages 4 to 7 into images.
To convert only the first page of a PDF:
Configure DPI Quality of the Images
Using pdftoppm, you can also change the DPI of the images. DPI stands for dots per inch and refers to the resolution of an image. By default, the tool generates images with a DPI of 150. However, you can specify a custom number to pdftoppm as well.
You can use the -rx and -ry flags to configure the DPI quality of the output images.
Adjust the Colors of the Output Images
To add color filters to the output images, you simply need to replace the image format with the filter name.
You can convert the PDF to grayscale images using the -gray flag. The generated file will have the PGM extension.
To generate monochrome images with pdftoppm:
Convert Password-Protected PDF Files
To convert password-protected PDF files using pdftoppm, use the -opw and -upw flags. The -opw and -upw flags stand for owner password and user password respectively.
Make sure to replace password with the password of the PDF document.
Quickly Convert PDF to Images on Linux
Pdftoppm is a reliable tool if you want to convert a PDF document to images. The utility gives you the control to configure image extension, name, and resolution. And the ability to do all of this directly from the Linux terminal is a cherry on top.
There are several PDF editors for Linux that provide you various tools to modify documents efficiently. You can also extract images from a PDF document easily if you feel the need.