Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash convert to pdf

Tags:

bash

How can I use both ls and convert to transform all images files in a directory to a pdf ? Also I need to put the files in a certain order for example files like AA1.png,AA11.png need to respect this logical order.

Update (ls) and (convert) are available , but how can I used them together ?

like image 615
johnlemon Avatar asked Nov 20 '10 18:11

johnlemon


1 Answers

To convert to a single PDF can be done in a single command:

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

Remember to include the -compress jpeg flag, or it'll store the images uncompressed and result in a massive PDF.

ImageMagick (via convert) requires Ghostscript (gs) to be installed in order to process PDFs I believe. Beware of memory issues if you are adding a lot of JPEGs at once.

As for your 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 the various sorting options available.

like image 105
Orbling Avatar answered Nov 10 '22 10:11

Orbling