All Tools / Blog / How to Convert an Image to PDF (Free)

How to Convert an Image to PDF (Free)

3 min read

Converting an image to PDF fixes the layout for printing, satisfies file format requirements, and bundles multiple pages into one file. None of it requires paid software.

In the browser

Drag images into the image-to-pdf tool. Reorder the pages if needed, then download the PDF. The tool runs client-side — files never leave your device. Supported formats: JPEG, PNG, WebP, GIF.

img2pdf (command line, lossless)

img2pdf places images into a PDF container without re-encoding them. A JPEG input stays as a JPEG inside the PDF — no quality loss from compression.

pip install img2pdf

# Single image
img2pdf image.jpg -o output.pdf

# Multiple images (each becomes one page)
img2pdf page1.jpg page2.jpg page3.jpg -o output.pdf

# All JPEGs in a folder, sorted by name
img2pdf $(ls *.jpg | sort) -o combined.pdf

# Set page size to A4
img2pdf image.jpg --pagesize A4 -o output.pdf

Unlike ImageMagick or Ghostscript, img2pdf doesn't decompress and recompress the image data. The output PDF has identical image quality to the input.

ImageMagick (command line)

# Single image
convert image.jpg output.pdf

# Multiple images into one PDF
convert page1.jpg page2.jpg page3.jpg output.pdf

# Set DPI for correct physical sizing
convert -density 150 image.jpg output.pdf

# PNG with transparency — flatten to white before converting
convert image.png -background white -flatten output.pdf

On Ubuntu, ImageMagick often blocks PDF output by default. If you get "not authorized":

sudo nano /etc/ImageMagick-6/policy.xml
# Find: <policy domain="coder" rights="none" pattern="PDF" />
# Change to: <policy domain="coder" rights="read|write" pattern="PDF" />

Python: Pillow

from PIL import Image

# Single image to PDF
with Image.open('image.jpg') as img:
    img.convert('RGB').save('output.pdf')

# Multiple images into one PDF
images = [Image.open(f).convert('RGB') for f in ['page1.jpg', 'page2.jpg', 'page3.jpg']]
images[0].save('output.pdf', save_all=True, append_images=images[1:])

Python: img2pdf (lossless)

import img2pdf

# Single image
with open('output.pdf', 'wb') as f:
    f.write(img2pdf.convert('image.jpg'))

# Multiple images
with open('output.pdf', 'wb') as f:
    f.write(img2pdf.convert(['page1.jpg', 'page2.jpg', 'page3.jpg']))

Combine a folder of scanned pages

import img2pdf
from pathlib import Path

pages = sorted(Path('scans/').glob('*.jpg'))
with open('document.pdf', 'wb') as f:
    f.write(img2pdf.convert([str(p) for p in pages]))
print(f'Combined {len(pages)} pages into document.pdf')

Sorting by filename keeps pages in order. If your scanner names files by date or sequence number, sorted() handles that automatically.

Page size and DPI

Most converters set the PDF page size to match the image dimensions exactly. For standard paper sizes:

# img2pdf: fit image to A4 page
img2pdf image.jpg --pagesize A4 -o output.pdf

# ImageMagick: A4 at 150 DPI
convert -density 150 -page A4 image.jpg output.pdf

DPI guidance for scanned documents:

Use case DPI Notes
On-screen reading 96–150 Small file, readable
Standard printing 150–200 Good quality, reasonable size
Archive / legal 300 Large files; preserves fine detail

Key takeaways

  • img2pdf is the best command-line option for lossless conversion — it doesn't re-encode JPEG data.
  • Pillow's save('output.pdf', save_all=True, append_images=...) combines multiple images into one PDF.
  • PNG with transparency needs to be flattened to a white background before conversion.
  • Sort filenames before combining scanned pages or the page order will be wrong.
  • Use 150 DPI for screen-only documents; 300 DPI for print or archival.