One day I needed to make a big pdf file from many graphic files. There was no simply solution for this and I wrote this little shell script.
There are several programs, that can convert any file to pdf (for example OpenOffice). But if you have 100 separate files and you want to make a one book from them or print them, it's no so pleasant to do this manually, adding file by file to OpenOffice and then saving as a .pdf or printing. That's why I'm showing you my solution for this.
I'm using bash, so as every shell script we begin with
Then we will do good filenames (this means filenames in lowercase with no whitespaces)
#convert to lowercasefor i in*;
done#substitute whitespaces with underscoresfor i in*;
Note that this will work only in the current directory and will affect all the files in it. If you want to convert only the files of the certain type, substitute the * with your file extensions mask (for example *.jpg in my case). If you have images in format other than jpeg, you should convert them to jpeg first, for example with ImageMagick:
for i in*.png;
do convert $i`basename$i .png`.jpg;
Of course you can extend this with your own filetypes or convertors, or add more automatic. For example you might want to resize your images to reduce the disk usage:
for i in*.png;
do convert -resize800$i`basename$i .png`_resized.jpg;
This converts images to jpg, additionally resizes their width to the 800 pixels and maintains the height automatically.
But what must be done in any case - all the files must be converted to .ps. Use jpeg2ps:
for i in*.jpg;
do jpeg2ps $i>`basename$i .jpg`.ps;
For further actions we have at least two ways. If your end format is pdf, you can directly use GhostScript. If you want to have a book in ps format, you can use psmerge or GhostScript. So I've choosed the GhostScript because it's more multi-purpose: