Put a stamp on the last page of a PDF document

PDFTK, the swiss-knife pdf toolkit, can be used to put a stamp an all pages of a pdf file; but it is not possible to put the stamp on the last page only. There is a commercial tool "stamptk" available for this. But you can also workaround this with a few lines of shell code:

input="INPUT.pdf"
stamp="STAMP.pdf"
output="OUTPUT.pdf"
tmp1="tmp1.pdf"
tmp2="tmp2.pdf"

pdftk "$input" cat end output "$tmp1"
pdftk "$tmp1" stamp "$stamp" output "$tmp2"
pdftk "$input" cat 1-r2 output "$tmp1"
pdftk "$tmp1" "$tmp2" cat output "$output"

I've put this code into a simple bash script and uploaded it to github: stamp-last-page.sh.

Comments

I believe I'm pretty sure, where you stumbled across this problem.