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:
#!/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 exist\n"
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 numbered\n"
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 !