Convert PDF File Into Images using Poppler pdftoppm

Convert PDF File Into Images using Poppler pdftoppm

At times, you may want to turn a PDF document into images. Instead of relying on online services (which might expose private files), you can use the pdftoppm tool from the Poppler utilities. This tutorial shows how to convert PDF file into images using Poppler pdftoppm.

Prepare environment

Before you begin, make sure that the Poppler utilities are installed on the system. If you are using Ubuntu, you can follow the installation guide.

Converting PDF to images

Let's download a sample PDF file to practice with:

curl -sSo test.pdf https://raw.githubusercontent.com/py-pdf/sample-files/master/004-pdflatex-4-pages/pdflatex-4-pages.pdf

To convert the PDF pages into the PNG format images, run the following command:

pdftoppm -png test.pdf test

This will produce separate images for each page:

test-1.png  test-2.png  test-3.png  test-4.png

Converting specific page range

If you only need a few pages, you can narrow down the output using -f (first page) and -l (last page). For example, to convert pages 2 through 4:

pdftoppm -png -f 2 -l 4 test.pdf test

Result:

test-2.png  test-3.png  test-4.png

Increasing image resolution

The pdftoppm converts PDF pages to images with a DPI of 150 by default. If you want sharper images (e.g., for printing), use the -r option to set DPI:

pdftoppm -png -r 300 test.pdf test

Leave a Comment

Cancel reply

Your email address will not be published.