Convert a folder of images into a multi-page pdf file using command line tools?

Requirements

ImageMagick

Type the follow line to commmand prompt for intall ImageMagick:

sudo apt-get install imagemagick

Convert from jpegs to PDF:

Go to the work directory (directory of jpegs):

cd work/directory/path

Convert the JPG files to PDF:

convert *.jpg foo.pdf

source : http://bitprison.net/jpg_to_pdf


Unfortunately convert changes the image before so to have minimal loss of quality, i.e. the quality of the original jpg, you need to use img2pdf, I use this commands:

A shorter one liner solution using only img2pdf

Make PDF

img2pdf *.jp* --output combined.pdf

Optionally add OCR to the output PDF

ocrmypdf combined.pdf combined_ocr.pdf

This was the original commands with more command and more tools needed:

  1. This to make a pdf file out of every jpg image without loss of either resolution or quality:

    ls -1 ./*jpg | xargs -L1 -I {} img2pdf {} -o {}.pdf

  2. This to concatenate the pdfpages into one:

    pdftk *.pdf cat output combined.pdf

  3. And last I add an OCRed text layer that doesn't change the quality of the scan in the pdfs so they can be searchable:

    pypdfocr combined.pdf


I highly recommend the Python CLI program img2pdf for lossless conversion:

https://gitlab.mister-muffin.de/josch/img2pdf

Example usage:

img2pdf img1.png img2.jpg -o out.pdf