#!/bin/sh
#
# (cc) Peter Gervai, 2011
# cc-by-sa-3.0
#
# remove private info from PDFs
#

if [ "$1" == "" ]; then
	echo " "
	echo "pdf metadata cleaner v1.00 by Peter 'grin' Gervai, 2011"
	echo " "
	echo "Usage: $0 filename.pdf"
	echo " "
	exit 0
fi 

T=`mktemp /tmp/pdfanon.XXXXXXXX`

# clean and dump InfoKeys
pdftk "$1" dump_data |  awk '/InfoValue/ {print $1}; !/InfoValue/ {print }' > $T
# update empty keys in pdf
pdftk "$1" update_info $T output "$1_new.pdf"
mv "$1" "$1.bak"
mv "$1_new.pdf" "$1"
echo  "$1.pdf written, old one renamed to $1.bak. Have a nice day!"

rm $T
