Convert a folder of images into a multi-page pdf file using command line tools?
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:
-
This to make a
pdf
file out of everyjpg
image without loss of either resolution or quality:ls -1 ./*jpg | xargs -L1 -I {} img2pdf {} -o {}.pdf
-
This to concatenate the
pdf
pages into one:pdftk *.pdf cat output combined.pdf
-
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
Related videos on Youtube
Somebody still uses you MS-DOS
Updated on September 18, 2022Comments
-
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 almost 13 yearsI found the solution myself, but you answered with more details. This was so simple I'm even ashamed of.
-
Vishwanath Dalvi almost 13 years^you r welcome!
-
tanius almost 9 yearsHmm, does not yet crop to A4 aspect ratio though ;)
-
phrogg almost 6 yearsIf you have the images in sub folders use this
convert */*.jpg foo.pdf
-
phrogg almost 6 yearsI 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?