A friend had a small problem to add a page number on a PDF with a lot of pages.
After a quick chat, I have built this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/bin/bash # Author: Brice Lilot # Contact: brice_lilot [at] visualstation [dot] be # Website: http://www.visualstation.be/ # Revision: 0.1 # Last modification: # * 2012-05-09: # - First shot ! # if [ -d $1 ] then printf "The directory already existn" cd $1 rm -rf *.jpg else mkdir $1 cd $1 fi whereismyfont=`find /usr/share/fonts -iname "DejaVuSans.ttf"` gs -dBATCH -dNOPAUSE -dSAFER -sDEVICE=jpeg -dJPEGQ=95 -r600x600 -sOutputFile=./$1-page-%d.jpg ../$1.pdf >> /dev/null cFiles=`find . -iname "*.jpg" | wc -l` for (( i=1; i <= $cFiles; i++)) do mogrify -quality 100% -font $whereismyfont -pointsize 90 -draw "gravity southeast fill #000000 text 600,300 '$i/$cFiles'" $1-page-$i.jpg printf "Page $i converted and numberedn" done param="" for (( i=1; i <= $cFiles; i++)) do dimension=$(identify -format "%[fx:(w)] %[fx:(h)]" "$1-page-${i}.jpg") param="${param} >>/PageSize [${dimension}]<< setpagedevice ($1-page-${i}.jpg) viewJPEG showpage" done gs -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o "$1_final.pdf" viewjpeg.ps -c "${param}" |
Have fun !