Guides 11792 Published by

This guide walks you through turning a folder of JPG photos into a single PDF straight from the command line, stressing speed and reproducibility without any GUI tools. It starts with installing ImageMagick on Linux, then shows a simple one‑liner that concatenates all JPEG files in alphabetical order, and offers ways to sort them by filename if needed. Advanced tips cover adjusting DPI for print quality, adding watermarks, creating thumbnail grids with montage, and even using Ghostscript for tighter compression control. Overall it’s a quick, practical reference for batch‑converting images into PDFs on headless or minimal systems.



How to Convert JPG Images to PDF Using the Terminal (No GUI Needed)

If you’ve ever been handed a folder full of photos and the only thing that will make sense is a single PDF, this guide shows you how to do it straight from the command line. No need for a fancy previewer or an online converter.

Why Convert From the Terminal?
  • Speed – One‑liner commands can batch thousands of files in seconds.
  • Reproducibility – Store the script, run it again on future trips without fumbling through menus.
  • Headless environments – If you’re on a server or a minimal install that doesn’t have a GUI, the terminal is your only friend.

I once had to turn 260 wedding photos into a PDF for an old‑school client who insisted on a physical copy. The GUI tools on my laptop were slow and kept prompting me to save each image individually. Using the terminal saved me hours and gave me a clean, single file that the client could print in one go.

Prerequisites: Install ImageMagick

ImageMagick’s convert command is the workhorse for this task. On Debian‑based systems:

sudo apt-get update && sudo apt-get install imagemagick -y

ImageMagick understands almost every image format and can stitch them into a PDF in one go, without any intermediate conversions.

Step‑by‑Step: One‑liner to PDF

1. Navigate to the folder

   cd ~/Pictures/Trip2024

Keeps the command short and ensures you’re working on the right files.

2. Run convert with a glob pattern

   convert *.jpg output.pdf

What it does: For each JPG file, ImageMagick reads the image data, appends it to the PDF stack, and writes a single output.pdf. The order follows your filesystem’s sort – usually alphabetical. If you need a different order (by date taken or custom numbering), sort first:

   convert $(ls -1v *.jpg) final_trip.pdf

3. Check the PDF

   ls -lh output.pdf

A quick size check tells you whether the conversion happened.

That’s it! No GUI, no manual saving.

Advanced Tweaks
  • Set DPI (image quality) – By default ImageMagick uses 72 dpi. For print‑ready PDFs:
  convert -density 300 *.jpg output.pdf
  • Add a watermark or caption – Use label: to prepend text on each page.
  convert *.jpg -gravity SouthEast -annotate +10+10 ":copyright: 2024" final_watermark.pdf
  • Create a multi‑column PDF – If you want thumbnails, use the montage command before converting:
  montage -tile 2x2 -geometry 400x300 *.jpg temp.jpg && convert temp.jpg final_grid.pdf
When to Use Ghostscript Instead

If ImageMagick is installed but you want tighter control over PDF compression or page size, Ghostscript’s gs can be handy:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=compressed.pdf *.jpg

This forces each JPG to be compressed into a single PDF with minimal overhead—great for low‑bandwidth uploads.

Wrap‑Up

Now you can turn any batch of JPEGs into a tidy PDF faster than your coffee will cool. Drop the terminal, grab the PDF, and send it off—no extra software required.