#!/bin/sh 
modulo=4 
#count page numbers
p=$(pdfinfo $1 | grep Pages | sed 's/[^0-9]*//') 
n=$(($p % modulo))
#we store the number of Bs for pdftk in this string
b=''
#accumulate Bs until we reach a multiple
while [ $n -ne 0 ]; do
  b=$b\ B
  n=$(($n - 1))
  done
pdftk A=$1 B=blank.pdf cat A $b output $2

