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.
U开发者_如何学Cpdate (ls) and (convert) are available , but how can I used them together ?
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.
https://gitlab.mister-muffin.de/josch/img2pdf
In all of the proposed solutions involving ImageMagick (i.e. convert
), the JPEG data gets fully decoded and re-encoded. This results in generation loss, as well as performance "ten to hundred" times worse than img2pdf.
If you have a lot of 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
for image in `ls *.png`; do
# call convert or whatever here
convert $image `basename $image .png`.pdf
done
精彩评论