Bash convert to pdf

How can I use both ls and convert to convert all image files to a directory in pdf? I also need to put the files in a specific order, for example, files such as AA1.png, AA11.png must follow this logical order.

Updates are available (ls) and (convert), but how can I use them together?

+6
bash
source share
4 answers

To convert to a single PDF file, you can run one command:

convert -compress jpeg *.jpg my-jpegs.pdf 

Remember to enable the -compress jpeg flag, or it will save uncompressed images and result in a massive PDF file.

ImageMagick (via convert) requires Ghostscript (gs) to be installed to handle PDF files, which I assume. Beware of memory problems if you add a lot of JPEGs at the same time.

As for logical ordering, you can use ls in combination with convert to get the list in order.

Something along the lines of:

 convert -compress jpeg `ls *.png` my-jpegs.pdf 

See ls --help for various sorting options available.

+7
source share

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

In all proposed ImageMagick related solutions (i.e., convert ), JPEG data is fully decoded and transcoded. This leads to loss generation , as well as to productivity ten times more than img2pdf.

+4
source share

If you have many files:

 convert -limit memory 1 -limit map 1 *.jpg foo.pdf 

see here

or with compression

 convert -limit memory 1 -limit map 1 -compress jpeg -quality 85 *.jpg foo.pdf 
+1
source share
 for image in `ls *.png`; do # call convert or whatever here convert $image `basename $image .png`.pdf done 
0
source share

All Articles