Home / Alt manpages / pdftocairo(1)

  • pdftocairo(1)
  • User command
  • linux

Convert PDF Pages to Images and Vector Files with pdftocairo

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 commands 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 using your distribution's normal package process. That changes system state and may require elevated privileges, so it is outside the conversion workflow. Checkpoint: continue only when 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 that an existing file is not 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 that you should add .png to yourself. The tool supplies the page number and type. For a multi-page PDF, expect one image for each 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 in 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, omit it and use the numbered output files.

To make a smaller preview, set the long side with -scale-to. The other dimension follows the page 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. These settings affect image output. A higher PPI normally means larger files and more memory use, so increase it for a stated reason such as print-quality text.

4. Choose colour, transparency and cropping deliberately

Use -gray for grayscale PNG or JPEG output, and -mono for a monochrome PNG or TIFF. Use -transp for 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

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

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:

$ 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 that their format cannot represent natively. The resolution options control that fallback rasterisation, 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 by the manpage. For PostScript or PDF output, -paper match or -origpagesizes preserves page sizing when that is your requirement.

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. For example, 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 performed 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. Options also have format limits, so read the local manpage when combining cropping, paper sizing or transparency options.

Capture the exit status immediately 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 status 1 for an error opening a PDF, 2 for an output-file error, 3 for a PDF-permissions error, 4 for an ICC-profile error and 99 for 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.

Encrypted PDFs may require -upw for the user password or -opw for the owner password. Supplying an owner password bypasses security restrictions. Treat passwords as sensitive: avoid putting them in shared process listings or shell history, and prefer a controlled environment if policy permits. Do not try to defeat a document's access controls without authorisation.

Done means

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