Convert PDF to PNG, JPEG in Ubuntu

PDF stands for Portable Document Format. It was developed by Adobe in the year 1993. In this article, we would discuss how to convert PDF to PNG, JPEG and various other image file formats in Ubuntu.

Since an image format like PNG, JPEG etc. is easily accessible. Therefore, we may think of converting our PDF to an image format before sharing it. Or, there could be some other reason.

First, we would install a package poppler-utils through standard Ubuntu repository. This would enable us to use the command-line utility – pdftoppm. Then, we would illustrate how to convert PDF to PNG, JPEG and various other image file formats.

Note: Following installation operations require you to have superuser privileges. In case you don’t have one, then we advise you to contact your System Administrator for assistance.

Install poppler-utils in Ubuntu

The package poppler-utils is available through standard Ubuntu repository. Therefore, first update the repository to make the latest version of the package available. Hence, open a terminal and issue the following –

sudo apt update

Then, to install the package –

sudo apt install poppler-utils

Now, lets say we have a PDF example.pdf (containing 25 pages). We will illustrate how to convert it in various image file formats. Various useful options which can be utilised with pdftoppm command-line utility are discussed next.

Convert PDF to PNG

The easiest way to convert all the pages of PDF to PNG is –

pdftoppm -png <input_file> prefix_output_filename

For instance,

pdftoppm -png example.pdf N

where,

-png is the image file format the PDF is converted to,
N is the prefix for the output file and,
example.pdf is the <input_file>

Output file name would be – (N-01.png; N-02.png ….)

Consider a scenario wherein we may specify the page range to convert

pdftoppm -f number -l number -png <input_file> prefix_output_filename

For instance,

pdftoppm -f 5 -l 15 -png example.pdf N

where,

-f number – first page to convert and,
-l number – last page to convert.

To convert only odd numbered pages

pdftoppm -o -png <input_file> prefix_output_filename

For instance,

pdftoppm -o -png example.pdf N

To convert only even numbered pages

pdftoppm -e -png <input_file> prefix_output_filename

For instance,

pdftoppm -e -png example.pdf N

To specify image resolution (default is 150 DPI) –

pdftoppm -r number -png <input_file> prefix_output_filename

For instance,

pdftoppm -r 300 -png example.pdf N

where,

-r number – to specify image resolution (in this case it was 300 DPI)

Convert PDF to JPEG

All the options will remain the same, we just have to replace -png in the above code with -jpeg.

pdftoppm -jpeg <input_file> prefix_output_filename

For instance,

pdftoppm -jpeg example.pdf N

Convert PDF to gray (grayscale PGM)

Here also, all options will remain the same – we have to just replace -png in the above code with -gray.

pdftoppm -gray <input_file> prefix_output_filename

For instance,

pdftoppm -gray example.pdf N

Convert PDF to mono (monochrome PBM)

Similarly, just replace -png in the above code with -mono.

pdftoppm -mono <input_file> prefix_output_filename

For instance,

pdftoppm -mono example.pdf N

Convert PDF to TIFF

Again, replace -png in the above code with -tiff.

pdftoppm -tiff <input_file> prefix_output_filename

For instance,

pdftoppm -tiff example.pdf N

In conclusion, we have discussed how to convert PDF to PNG, JPEG and various other image file formats.

Similar Posts