Home / Alt manpages / pdftoppm(1)

  • pdftoppm(1)
  • User command
  • linux

Convert PDF Pages to PNG, JPEG or TIFF with pdftoppm

You will finish with a repeatable command for turning a PDF into image files, selecting pages and controlling the output size without accidentally creating a directory full of unneeded files. The examples use pdftoppm from Poppler 24.02.0, provided here by poppler-utils version 24.02.0-1ubuntu9.9.

Allow about fifteen minutes. You need a shell, a readable PDF, and enough space for the generated images. The commands below are ordinary user commands. You do not need sudo unless the input or destination is deliberately protected from your account.

1. Check the installed command

Start by checking which binary will run and recording its version. This avoids debugging a different Poppler installation later:

$ command -v pdftoppm
/usr/bin/pdftoppm
$ pdftoppm -v
pdftoppm version 24.02.0
Copyright 2005-2024 The Poppler Developers - http://poppler.freedesktop.org

The local manual describes the older Xpdf-style interface and names the default output as 150 DPI. The installed program reports Poppler 24.02.0, so check pdftoppm -h on another host before copying an option-heavy command between distributions.

Checkpoint

You know the path and version of the executable that will process the PDF.

2. Convert every page to PNG

Give the command an input PDF followed by an output root. The root is a filename prefix, not a directory name. With a multi-page document, the command adds a hyphen and the page number:

$ mkdir -p /tmp/pdftoppm-output
$ pdftoppm -png /path/to/input.pdf /tmp/pdftoppm-output/page
$ find /tmp/pdftoppm-output -maxdepth 1 -type f -name 'page-*.png' -print
/tmp/pdftoppm-output/page-1.png
/tmp/pdftoppm-output/page-2.png

The exact list depends on the PDF. PNG output is usually a sensible choice for text, diagrams and screenshots because it preserves sharp edges without JPEG artefacts. If you omit -png, the default is colour PPM output, which is often much larger and less convenient for other tools.

Do not use a valuable existing prefix until you have checked it. An output file with the same name can be replaced by a later conversion, depending on the destination and permissions. The safe example uses a fresh directory under /tmp; remove that test directory only when you no longer need it.

3. Render one page or a page range

Use -f for the first page and -l for the last. Page numbers are inclusive:

$ pdftoppm -png -f 3 -l 5 /path/to/input.pdf /tmp/pdftoppm-output/selected
$ find /tmp/pdftoppm-output -maxdepth 1 -type f -name 'selected-*.png' -print | sort
/tmp/pdftoppm-output/selected-3.png
/tmp/pdftoppm-output/selected-4.png
/tmp/pdftoppm-output/selected-5.png

This is safer than converting a large document and deleting most of the results afterwards. If you need alternating pages, -o selects odd-numbered pages and -e selects even-numbered pages. Keep the page range and parity filters together only when that combination is genuinely what you want.

-singlefile is different: it writes only the first page and does not append a page number. It does not mean "use one file for the whole document". A useful thumbnail command is:

$ pdftoppm -png -singlefile -scale-to 1200 /path/to/input.pdf /tmp/pdftoppm-output/cover
$ file /tmp/pdftoppm-output/cover.png
/tmp/pdftoppm-output/cover.png: PNG image data, ...

The dimensions and the remainder of file output vary with the PDF. The command's exit status is the first check; the file test confirms that the expected output exists.

4. Choose resolution or pixel dimensions

The default resolution is 150 DPI for both axes. Set both axes with -r when you want a predictable raster density:

$ pdftoppm -png -r 200 -f 1 -l 1 /path/to/input.pdf /tmp/pdftoppm-output/page-200dpi
$ identify /tmp/pdftoppm-output/page-200dpi-1.png

identify is an ImageMagick command and is not part of poppler-utils; if it is absent, use another image-information tool or inspect the file in an image viewer. The conversion itself does not depend on it.

For a maximum pixel size instead of a DPI target, use -scale-to. It fits the long side of every page to the number you provide and preserves the page aspect ratio:

$ pdftoppm -png -scale-to 1600 -f 1 -l 1 /path/to/input.pdf /tmp/pdftoppm-output/page-1600
$ file /tmp/pdftoppm-output/page-1600-1.png

Use -scale-to-x and -scale-to-y when the output box must have explicit horizontal and vertical limits. The manual permits -1 for the other dimension when it should follow the aspect ratio. Test a representative portrait and landscape page: rotation and page geometry can make an assumed width or height misleading. The installed help output is the authority if a locally packaged version differs.

Checkpoint

Choose either a density target such as 200 DPI or a pixel target such as 1600 pixels. Do not add both casually and assume the result is governed by the last option.

5. Pick the output format and quality

Use -gray for grayscale PGM output or -mono for monochrome PBM output. These are useful when the downstream system expects those formats. For common exchange formats:

$ pdftoppm -jpeg -jpegopt quality=85,progressive=y /path/to/input.pdf /tmp/pdftoppm-output/photo
$ pdftoppm -tiff -tiffcompression deflate -f 1 -l 2 /path/to/input.pdf /tmp/pdftoppm-output/archive

The JPEG quality value must be an integer from 0 to 100. Progressive JPEG and Huffman optimisation are separate settings; optimisation can make files smaller but requires another pass. TIFF compression accepts none, packbits, jpeg, lzw or deflate, and the manual says TIFF defaults to none. Avoid JPEG for fine text or line art unless the resulting artefacts are acceptable.

6. Use a PDF from standard input

A single hyphen in the PDF-file position tells pdftoppm to read the PDF from standard input. This is useful in a pipeline, but it makes the source less obvious when you revisit shell history:

$ cat /path/to/input.pdf | pdftoppm -png -f 1 -l 1 - /tmp/pdftoppm-output/stdin-page
$ test -s /tmp/pdftoppm-output/stdin-page-1.png && echo 'PNG created'
PNG created

Do not pass an empty or unrelated stream and then diagnose the result as a rendering problem. If the PDF is encrypted, -upw supplies a user password. -opw supplies an owner password and can bypass PDF security restrictions, so treat it as security-sensitive: do not put a real password in a shared shell history, process listing or ticket.

7. Diagnose failures without guessing

Use the exit status and the documented exit codes:

  • 0: no error.
  • 1: the PDF could not be opened.
  • 2: an output file could not be opened.
  • 3: an error related to PDF permissions.
  • 99: another error.

For a missing input file, fix the path or permissions first. For code 2, check that the output directory exists, is writable, and has enough space. The command does not create missing parent directories, which is why the examples create the temporary output directory first. A non-zero status is a failure even if earlier pages were written; inspect and discard partial output before retrying with the same prefix.

Use -progress when a long conversion needs visible progress. It writes the current page, final page and output path to standard error. Use -q only when a quiet pipeline is more useful than diagnostics. -cropbox changes the page box used for generation, and -hide-annotations suppresses annotations. These can change the visible result, so compare a page with and without the option before applying it to a batch.

Done means

  • You checked the installed Poppler version and executable path.
  • You used a deliberate output root and confirmed the generated filenames.
  • You selected a page range or single-page mode consciously.
  • You chose DPI or pixel scaling for a stated reason.
  • You selected PNG, JPEG, TIFF, PGM, PBM or PPM based on the next tool's needs.
  • You checked the exit status and know what the documented failure codes mean.
  • You can remove the temporary test files without touching the original PDF.