Home / Alt manpages / pdftocairo(1)

  • pdftocairo(1)
  • User command
  • linux

Convert PDF Pages to Images and Vector Files with pdftocairo

Screenshot tools mangle PDFs and Preview exports look wrong, so pdftocairo is the reliable way to turn pages into real images or vectors. You will finish with repeatable commands for turning a PDF into PNG or JPEG images, selecting pages and dimensions, and producing a vector PDF copy when that is the better fit. The examples use pdftocairo 24.02.0 from Ubuntu package poppler-utils 24.02.0-1ubuntu9.9.

Allow about fifteen minutes. You need a shell, a readable PDF and the poppler-utils package. These are ordinary user commands: they do not need sudo. Do not use a PDF containing sensitive information in a shared output directory, and do not put passwords directly into shell history.

1. Check the installed command

Confirm which executable will run and record its version. This is a read-only check:

$ command -v pdftocairo
/usr/bin/pdftocairo
$ pdftocairo -v 2>&1
pdftocairo version 24.02.0
Copyright 2005-2024 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011, 2022 Glyph & Cog, LLC

If the command is missing, install poppler-utils through your distribution's normal package process. That changes system state and may need elevated privileges, so it sits outside the conversion workflow itself.

Checkpoint

Continue only once pdftocairo -v prints a version.

2. Render a PDF to PNG

The general form is pdftocairo -png PDF-file output-prefix. PNG, JPEG and TIFF output create one file per page, adding a page number and extension to the output prefix. Use a fresh directory so an existing file is never accidentally replaced:

$ mkdir -p "$HOME/tmp/pdf-render"
$ pdftocairo -png \
    /path/to/input.pdf \
    "$HOME/tmp/pdf-render/page"
$ find "$HOME/tmp/pdf-render" -maxdepth 1 -type f -printf '%f\n' | sort
page-1.png
page-2.png

The output prefix is not a filename stem you should add .png to yourself: the tool supplies the page number and type. For a multi-page PDF, expect one image per converted page. The default image resolution is 150 PPI.

Checkpoint

Inspect one result without changing it:

$ file "$HOME/tmp/pdf-render/page-1.png"
/home/you/tmp/pdf-render/page-1.png: PNG image data, ...

The dimensions and the rest of the file output depend on the PDF page size. The ellipsis above is explanatory, not text to paste.

3. Select pages and make a single image

Use -f for the first page and -l for the last. Page numbers are inclusive. Add -singlefile when you want only the first page of the selected range and do not want digits cluttering the output name:

$ pdftocairo -png -f 3 -l 3 -singlefile \
    /path/to/input.pdf \
    "$HOME/tmp/pdf-render/page-3"
$ file "$HOME/tmp/pdf-render/page-3.png"
/home/you/tmp/pdf-render/page-3.png: PNG image data, ...

-singlefile does not mean "combine every selected page". It writes only the first page selected. If you need several pages, drop it and use the numbered output files instead.

For a smaller preview, set the long side with -scale-to. The other dimension follows the page's own aspect ratio:

$ pdftocairo -jpeg -f 1 -l 1 -singlefile -scale-to 600 \
    /path/to/input.pdf \
    "$HOME/tmp/pdf-render/preview"
$ file "$HOME/tmp/pdf-render/preview.jpg"
/home/you/tmp/pdf-render/preview.jpg: JPEG image data, ...

For predictable raster density instead, use -r, or set horizontal and vertical density independently with -rx and -ry. A higher PPI normally means larger files and more memory use, so push it up only for a real reason such as print-quality text.

4. Choose colour, transparency and cropping deliberately

  • -gray. Greyscale PNG or JPEG output.
  • -mono. Monochrome PNG or TIFF.
  • -transp. A transparent page background with PNG output.

These are output choices, not repairs for a PDF whose content already has a coloured background.

The crop options -x, -y, -W and -H use pixels for image output. -cropbox uses the PDF CropBox rather than its MediaBox. Try a crop in a separate directory first:

$ mkdir -p "$HOME/tmp/pdf-crop-test"
$ pdftocairo -png -f 1 -l 1 -singlefile \
    -x 100 -y 100 -W 1200 -H 900 \
    /path/to/input.pdf \
    "$HOME/tmp/pdf-crop-test/crop"
$ test -s "$HOME/tmp/pdf-crop-test/crop.png" && echo "crop written"
crop written

Warning

Coordinates and dimensions that do not suit the page can chop off useful content. Compare the cropped file against the original before you replace anything. If a command overwrote a file, recovery depends on your backups or filesystem snapshots; pdftocairo has no undo.

5. Keep vector output when rasterisation is the wrong choice

Use one of the vector format options when you need a PDF, PostScript, EPS or SVG file rather than page images. For these formats, the output argument is the complete filename, not a prefix:

$ pdftocairo -pdf -f 1 -l 1 \
    /path/to/input.pdf \
    "$HOME/tmp/pdf-render/first-page.pdf"
$ file "$HOME/tmp/pdf-render/first-page.pdf"
/home/you/tmp/pdf-render/first-page.pdf: PDF document, version 1.7

Unlike PNG output, this does not create a numbered series. PDF, PS, EPS and SVG can still rasterise regions their format cannot represent natively; the resolution options control that fallback, with 150 PPI as the default.

EPS contains one image, so use -f and -l to select exactly one page. EPS also cannot use the paper-size options described in the manpage. For PostScript or PDF output, -paper match or -origpagesizes preserves page sizing when that is what you need.

6. Use standard input and output only within their limits

A PDF filename of - reads from standard input. An output filename of - writes to standard output, but stdout is not valid for image formats unless -singlefile is also used. This sends one PNG to a file:

$ cat /path/to/input.pdf | \
    pdftocairo -png -f 1 -l 1 -singlefile - - \
    > "$HOME/tmp/pdf-render/stdin-page.png"
$ test -s "$HOME/tmp/pdf-render/stdin-page.png" && echo "standard-input render written"
standard-input render written

The trailing redirection is done by your shell, not by pdftocairo. Avoid piping diagnostic output into a binary file. If you need several image pages, write to a prefix on disk instead of stdout.

7. Diagnose failures without guessing

Exactly one output format option is required. A command that omits -png, -jpeg, -tiff, -pdf, -ps, -eps or -svg is incomplete, and options also have format limits, so check the local manpage when combining cropping, paper sizing or transparency options.

Capture the exit status right after a failed run:

$ pdftocairo -png /path/to/missing.pdf "$HOME/tmp/pdf-render/missing"
Syntax Error: Couldn't open file '/path/to/missing.pdf': No such file or directory.
$ printf 'exit status: %s\n' "$?"
exit status: 1

The Poppler tools use these exit codes:

  • 1. Error opening the PDF.
  • 2. Output-file error.
  • 3. PDF-permissions error.
  • 4. ICC-profile error.
  • 99. Another error.

A non-zero status is the useful signal; diagnostic wording can vary. Check the input path, destination permissions and option compatibility before reaching for sudo.

Security warning

Encrypted PDFs may need -upw for the user password or -opw for the owner password. Supplying an owner password bypasses security restrictions. Treat passwords as sensitive: keep them out of shared process listings and shell history, and do not try to defeat a document's access controls without authorisation.

Done means

  • Version confirmed. You checked the installed Poppler version and command path.
  • Format chosen. You selected exactly one output format and used a fresh destination.
  • Pages controlled. You can render a page range, a single preview and a vector output.
  • Prefix vs filename understood. You know the difference between an output prefix and a complete vector filename.
  • Output checked. You checked dimensions, files and exit status instead of trusting a silent command.
  • Risks flagged. You know that existing outputs, passwords and permission changes need separate care.