Convert PDF Pages to PNG, JPEG or TIFF with pdftoppm
Feed a PDF into the wrong converter and you get a folder full of junk files; pdftoppm gives you image output you can actually predict. You will finish with a repeatable command for turning a PDF into image files, selecting pages and controlling the output size without accidentally flooding a directory with unneeded files. The examples use pdftoppm from Poppler 24.02.0, provided here by poppler-utils version 24.02.0-1ubuntu9.9.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell, a readable PDF, and enough space for the generated images. These 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 saves you 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 usually suits text, diagrams and screenshots because it keeps sharp edges without JPEG artefacts. Omit -png and the default is colour PPM output, which is often much larger and less convenient for other tools.
Warning
Do not use a valuable existing prefix until you have checked it. An output file with the same name can be silently replaced by a later conversion, depending on the destination and permissions. The safe example above uses a fresh directory under /tmp; remove that test directory only once 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 whole large document and deleting most of the results afterwards. If you need alternating pages, -o selects odd-numbered pages and -e selects even-numbered ones. Only stack the page range and parity filters together when that combination is genuinely what you want.
-singlefile is different: it writes only the first page and skips the page number. It does not mean "use one file for the whole document". A useful thumbnail command looks like this:
$ 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 rest of the file output vary with the PDF. The command's exit status is the first check; the file test confirms the expected output actually exists.
4. Choose resolution or pixel dimensions
The default resolution is 150 DPI on 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, not part of poppler-utils; if it is missing, use another image-information tool or 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 give it and keeps the page's 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 needs explicit horizontal and vertical limits. The manual allows -1 for the other dimension when it should follow the aspect ratio. Test a representative portrait page and one that is wider than it is tall: 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 casually add both and assume the result is governed by whichever you typed last.
5. Pick the output format and quality
Use -gray for greyscale PGM output or -mono for monochrome PBM output; these suit downstream systems that expect 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 shrink files but needs 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. Handy in a pipeline, but it makes the source less obvious when you revisit shell history later:
$ 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 feed it an empty or unrelated stream and then diagnose the result as a rendering problem. If the PDF is encrypted, -upw supplies a user password. Security warning: -opw supplies an owner password and can bypass PDF security restrictions, so treat it as 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 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 up front. 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 matters more than diagnostics. -cropbox changes the page box used for generation, and -hide-annotations suppresses annotations. Both can change the visible result, so compare a page with and without the option before applying it to a whole batch.
Done means
- Version checked. You confirmed the installed Poppler version and executable path.
- Output root deliberate. You used a chosen output root and confirmed the generated filenames.
- Pages selected. You picked a page range or single-page mode consciously.
- Sizing justified. You chose DPI or pixel scaling for a stated reason.
- Format matched to purpose. You selected PNG, JPEG, TIFF, PGM, PBM or PPM based on the next tool's needs.
- Exit status checked. You know what the documented failure codes mean.
- Cleanup safe. You can remove the temporary test files without touching the original PDF.