PDF to Image Command line Examples

Use these command-line examples for common PDF to Image tasks. See the CLI guide for installation, input and output handling, and diagnostics.

You can run the examples below without account setup. The CLI uses demo credentials unless you have configured your own API credentials. Update the input URLs and filenames as needed.

Commands use POSIX-shell syntax, as in Bash or Zsh, and save results in the current directory.

Basic examples

These commands save the result with --output. See Handle the Result for output choices and failure handling.

Convert a file

Upload an existing invoice.pdf file.

pdf2image --force-zip \
    --output-format=png \
    --output invoice.zip \
    invoice.pdf

Convert a URL

pdf2image --force-zip \
    --output-format=png \
    --output invoice.zip \
    https://your-server.com/invoice.pdf

Read bytes from stdin

Read invoice.pdf through stdin. Use the same - input for bytes piped from another program.

pdf2image --force-zip \
    --output-format=png \
    --output invoice.zip \
    - < invoice.pdf

Customize page images

These examples use report.pdf, a three-page document with text, a chart, and vector graphics. The CropBox variant uses cropbox.pdf, a page with a predefined crop boundary.

Create page previews

Render page 1 of report.pdf directly as a PNG. Use 72 DPI for a compact preview or 300 DPI for more detail at higher pixel dimensions and file size. Selecting one page produces an image file without ZIP packaging.

Compact preview at 72 DPI

pdf2image --dpi=72 \
    --output-format=png \
    --print-page-range=1 \
    --output preview.png \
    report.pdf

High-resolution image at 300 DPI

pdf2image --dpi=300 \
    --output-format=png \
    --print-page-range=1 \
    --output page-300dpi.png \
    report.pdf

Render selected pages

Render pages 1 and 3 of report.pdf as PNG images in selected-pages.zip. Force ZIP packaging so the result stays an archive even if you later select just one page.

pdf2image --force-zip \
    --output-format=png \
    --print-page-range=1,3 \
    --output selected-pages.zip \
    report.pdf

Export a JPEG

Convert page 1 of report.pdf into page.jpg for applications that need JPEG input. JPEG is lossy and is not always smaller than PNG, especially for pages dominated by text and flat graphics.

pdf2image --output-format=jpg \
    --print-page-range=1 \
    --output page.jpg \
    report.pdf

Crop page images

Extract the chart from page 1 of report.pdf into chart.png, or honor the predefined CropBox in cropbox.pdf to remove its production margins.

The chart example fixes 144 DPI and uses pixel coordinates from the rendered page's top-left corner: X = 96, Y = 370, width = 1024, height = 384. Adjust the coordinates when changing the page layout or DPI. The CropBox variant uses the boundary already stored in the PDF.

Extract a chart region

pdf2image --crop-area-height=384 \
    --crop-area-width=1024 \
    --crop-area-x=96 \
    --crop-area-y=370 \
    --dpi=144 \
    --output-format=png \
    --print-page-range=1 \
    --output chart.png \
    report.pdf

Use the PDF's CropBox

pdf2image --output-format=png \
    --print-page-range=1 \
    --use-cropbox \
    --output cropped-page.png \
    cropbox.pdf

Create a grayscale image

Render page 1 of report.pdf into grayscale.png, replacing colors with shades of gray while preserving the page dimensions.

pdf2image --output-format=png \
    --print-page-range=1 \
    --use-grayscale \
    --output grayscale.png \
    report.pdf