I have a bunch of small scripts for converting every page of a pdf
into an image, and then putting it back together into a pdf. The file
size obviously grows a LOT. Here is the relevant code.

-- begin mypdftojpg --
#!/bin/bash

f=$1

mkdir "$f"_imgs
i="1"

pc=`pdfinfo "$f" | grep Pages | cut -d ":" -f 2`

#echo Converting "$f"..

while [ $i -le $pc ]; do
        pdftoppm -gray -r 280 -f $i "$f" | ppmtojpeg --quality=90 >
"$f"_imgs/$i.jpg
        echo "100*$i/$pc" | bc
        i=$[$i+1]
done

echo 100
-- end mypdftojpg --

Another script to convert jpegs into a pdf.

-- begin myjpgtopdf --
#!/bin/bash

f=`ls *jpg | sort -n `

pc=`ls *jpg | wc -l`
pc=$(($pc+1))

#mogrify -format pdf *jpg

c=0
for i in *jpg; do
        c=$(($c + 1))
        mogrify -format pdf "$i"
        echo "100*$c/$pc" | bc
done

fp=`ls *pdf | grep -v out.pdf | sort -n `
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=out.pdf -dBATCH $fp
echo 100
-- end myjpgtopdf --


The above two scripts are invoked from another script which uses it like this..

-- calling script --
mypdftojpg "$1" | zenity --text "Printing progress: converting pages
to jpg" --progress --auto-close
cd "$1"_imgs
myjpgtopdf | zenity --text "Printing progress: converting jpg to pdf"
--progress --auto-close
-- end calling script --



Sharad

-- 
Mailing list guidelines and other related articles: http://lug-iitd.org/Footer

Reply via email to