SysTutorials

Merge JPG Images into PDF on Linux

· updated April 12, 2026

Converting a series of JPG images into a single PDF is useful for creating documents, presentations, or archiving scanned photos. Linux offers several tools for this task, each with different trade-offs between simplicity, quality preservation, and features.

For most cases, img2pdf is the best choice because it merges images without re-encoding or re-compressing them, preserving original quality:

img2pdf *.jpg -o output.pdf

To control the order of images, specify them explicitly:

img2pdf image1.jpg image2.jpg image3.jpg -o output.pdf

You can also set page size and margins:

img2pdf *.jpg -o output.pdf --imgsize 210x297mm --margin 10

The --imgsize flag accepts common sizes like A4, letter, or custom dimensions. If your images are already the right size, you can fit them to the page:

img2pdf *.jpg -o output.pdf --fit shrink

Install img2pdf on Debian/Ubuntu:

sudo apt install img2pdf

On RHEL/CentOS/Fedora:

sudo dnf install img2pdf

Using ImageMagick

ImageMagick’s convert command works but re-compresses images, reducing quality:

convert *.jpg output.pdf

This approach is slower and larger in file size compared to img2pdf. However, ImageMagick is useful if you need to manipulate images during conversion (resize, rotate, adjust colors):

convert *.jpg -resize 50% -quality 85 output.pdf

Using Ghostscript

For more control over PDF compression and settings, use Ghostscript:

convert *.jpg output.pdf && gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
  -dPDFSETTINGS=/ebook -o compressed.pdf output.pdf

Using PDFtk (for manipulation after creation)

If you need to merge PDFs that you’ve already created, or reorder pages:

pdftk page1.pdf page2.pdf output merged.pdf

Handling Specific Formats

For mixed image formats (JPG, PNG, TIFF):

img2pdf *.jpg *.png -o output.pdf

For images with rotation metadata:

img2pdf --auto-orient *.jpg -o output.pdf

Processing Large Image Sets

For directories with many images, sort them numerically:

img2pdf $(ls -v *.jpg) -o output.pdf

Or use find with numerical sorting:

find . -maxdepth 1 -name "*.jpg" -print0 | sort -z -V | xargs -0 img2pdf -o output.pdf

Adding OCR (Optional)

To make PDFs searchable, use OCRmyPDF after creation:

img2pdf *.jpg -o output.pdf
ocrmypdf output.pdf output-ocr.pdf

This requires ocrmypdf and Tesseract. Install on Debian/Ubuntu:

sudo apt install ocrmypdf tesseract-ocr

Performance Considerations

For archival or quality-critical work, always use img2pdf. Reserve ImageMagick and Ghostscript for cases where you need image manipulation or aggressive compression.

Troubleshooting Common Issues

When encountering problems on Linux systems, follow a systematic approach. Check system logs first using journalctl for systemd-based distributions. Verify service status with systemctl before attempting restarts. For network issues, use ip addr and ss -tulpn to diagnose connectivity problems.

Package management issues often stem from stale caches. Run dnf clean all on Fedora or apt clean on Ubuntu before retrying failed installations. If a package has unmet dependencies, try resolving them with dnf autoremove or apt autoremove.

These commands are frequently used alongside the tools discussed in this article:

Quick Verification

After applying the changes described above, verify that everything works as expected. Run the relevant commands to confirm the new configuration is active. Check system logs for any errors or warnings that might indicate problems. If something does not work as expected, review the steps carefully and consult the official documentation for your specific version.

← All posts