Monday, November 1, 2010

Convert .jpg to .pdf instantly! and combine multiple pdf to one

Hi all, recently i had to convert some .jpg files to pdf , i knew that it can be done via GIMP by exporting as pdf but going by the number of files , it would have taken a lot of time, so i googled and found this amazing tool called Imagemagick which one can find in the Ubuntu repository.
First you need to install it as:
sudo apt-get install imagemagick
and then convert simply as:
convert foo.jpg foo.pdf
Moreover i'm thinking of writing a bash script which would convert all the files at one go. It will take some time so keep watching.
Here's script i wrote to convert all the .jpg files in the current directory to .pdf:


#!/bin/bash
count=1;
for file in *.JPG;
do
echo "$file coverted to $count.pdf"
convert $file $count.pdf
let count=$count+1
done


Now to combine multiple pdfs to one , one needs to install two small packages:
gs and pdftk
next to combine use the following command:
pdftk *.pdf output combined.pdf
where combined.pdf is the new combined pdf formed.

Hope it was useful.
Proud to use open source :)

No comments:

Post a Comment