LinuxCommandLibrary

img2pdf

Convert images to PDF

TLDR

Convert one or more images to a single PDF, each image being on its own page

$ img2pdf [path/to/image1.ext path/to/image2.ext ...] --output [path/to/file.pdf]
copy

Convert only the first frame of a multi-frame image to PDF
$ img2pdf [path/to/file.gif] --first-frame-only --output [path/to/file.pdf]
copy

Auto orient the image, use a specific page size in landscape mode, and set a border of specific sizes horizontally and vertically
$ img2pdf [path/to/image.ext] --auto-orient --pagesize [A4^T] --border [2cm]:[5.1cm] --output [path/to/file.pdf]
copy

Shrink only larger images to a rectangle of specified dimensions inside a page with a specific size
$ img2pdf [path/to/image.ext] --pagesize [30cm]x[20cm] --imgsize [10cm]x[15cm] --fit [shrink] --output [path/to/file.pdf]
copy

Convert an image to PDF and specify metadata for the resulting file
$ img2pdf [path/to/image.ext] --title [title] --author [author] --creationdate [1970-01-31] --keywords [keyword1 keyword2] --subject [subject] --output [path/to/file.pdf]
copy

SYNOPSIS

img2pdf [OPTION...] [FILE...] [-o OUTFILE]

PARAMETERS

-o, --output=FILE
    Output PDF filename (required unless stdout).

-p, --pagesize=SIZE
    Page size (e.g., A4, letter, 210x297mm).

--border=W:H
    Page border width:height in mm (default: 0:0).

--fit=[shrink|expand|both]
    Fit images to page size.

--rotation=ANGLE
    Rotate pages (0, 90, 180, 270 degrees).

--nocrop
    Disable automatic cropping to image bounds.

--optimize=0|1|2
    PDF optimization level (2 most aggressive, lossless).

--password=PASSWORD
    Set owner password for PDF encryption.

--key-size=128|256
    Encryption key size in bits (default: 128).

--stdin-src
    Read images from stdin instead of files.

--version
    Print version and exit.

--help
    Show help and exit.

DESCRIPTION

img2pdf is a lightweight, command-line utility for converting images to PDF documents without any quality loss. It embeds original image data directly into the PDF, avoiding recompression, rescaling, or interpolation, which preserves pixel-perfect fidelity. This is ideal for archiving scans, photos, or high-resolution images.

Supporting formats like JPEG, PNG, TIFF, WebP via Pillow, it handles single or multiple images (each on its own page). Features include custom page sizes (e.g., A4, letter), fitting modes (shrink/expand/both), rotation, borders, cropping control, PDF optimization (reduces size losslessly), and AES encryption.

The tool is Python-based, fast for most uses, and produces standards-compliant PDFs readable everywhere. It's popular in workflows like batch-scanning documents or creating print-ready files, outperforming GUI tools or ImageMagick's convert in quality preservation and speed.

No GUI dependencies; install via pip or packages. Output can go to file or stdout for piping.

CAVEATS

Large images yield big PDFs; requires Pillow (>=5.0); no vector graphics support; limited to raster images.

EXAMPLES

img2pdf *.jpg -o output.pdf
img2pdf --pagesize A4 --fit shrink scan*.tiff -o doc.pdf
cat images/ | img2pdf --stdin-src -o out.pdf

INSTALLATION

Debian/Ubuntu: apt install img2pdf
pip: pip install img2pdf (installs Pillow auto).

HISTORY

Developed by Jakob Kummerow starting 2016; version 0.1.0 released May 2016. Actively maintained, now at v0.5+; popular for lossless conversion over ImageMagick alternatives.

SEE ALSO

Copied to clipboard