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

9,939

Solution 1

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

Solution 2

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

Solution 3

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
Share:
9,939

Related videos on Youtube

Somebody still uses you MS-DOS
Author by

Somebody still uses you MS-DOS

Updated on September 18, 2022

Comments

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS over 1 year

    I have a folder with 100 jpg images. I want to convert these images into a multi-page pdf file, with all the images (cropped to A4 size). They are already in the correct rotation.

    Which tools should I use?

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS almost 13 years
    I found the solution myself, but you answered with more details. This was so simple I'm even ashamed of.
  • Vishwanath Dalvi
    Vishwanath Dalvi almost 13 years
    ^you r welcome!
  • tanius
    tanius almost 9 years
    Hmm, does not yet crop to A4 aspect ratio though ;)
  • phrogg
    phrogg almost 6 years
    If you have the images in sub folders use this convert */*.jpg foo.pdf
  • phrogg
    phrogg almost 6 years
    I still have a problem he sorts everything like 1, 10, 100 and not 1,2,3,4,5,...,100,101,102 how do I fix this?