Skip to main content
1 of 9
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

There may be a simpler way, but basing one on this solution I simply copied /etc/enscript/simple.hdr to ~/.enscript/myheader.hdr just to play with it and then ... loop over your files...

#!/bin/bash

input="$1"    #the name of the source pdf
label="$2"    #any text you want to add to the footer
from=$3       #the page number you want to start from
output="$4"   #the name of your output file


#get the number of pages in the pdf
pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)

#calculate the last page number
to=$(($from+$pagenum-1))

enscript -L1 --header-font=Helvetica-Bold14 --fancy-header=myheader 
  --header="||" --footer="||$label $% $i" --output - < <(for i in $(seq $to); do echo;
      done) | ps2pdf - | pdftk - cat $from-$to output - | pdftk "$input" multistamp - output "$output.pdf"

Use enscript to produce a 100+pagenum-1 page pdf with the footer in place, pipe this to pdftk to remove the unwanted 99 pages and then pipe these pages back into pdftk stamping them over your input file with the multistamp option

for f in files; do thisScript $f "hello world" 100 ${f%.*}.numbered.pdf; done

The precise formatting can be finessed in myheader.hdr

bu5hman
  • 4.9k
  • 2
  • 16
  • 29