All posts

Images to PDF via CLI

Pack JPEG and PNG into one PDF with img2pdf, without recompression.

Open online converter

Packages to install

The img2pdf package embeds images into PDF as-is, without re-encoding them as JPEG.

img2pdf
apt install
sudo apt-get update
sudo apt-get install -y img2pdf

How to run the command

List images in page order and pass -o output.pdf. Command-line order becomes page order.

img2pdf
img2pdf photo.jpg -o album.pdf

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        img2pdf && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /work
docker build && docker run
docker build -t images-to-pdf .
docker run --rm -v "$PWD:/work" -w /work images-to-pdf \
  img2pdf photo.jpg -o album.pdf

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
img2pdf photo.jpg -o album.pdf
Example 2
img2pdf page1.png page2.jpg page3.png -o album.pdf