Last active
August 29, 2015 13:59
-
-
Save aschmoe/10776901 to your computer and use it in GitHub Desktop.
Secure pdfs with pdftk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for file in Dropbox/Taxes/{,**/,**/**/}*.pdf | |
do | |
protected=0 | |
passwordworks=1 | |
pdftk "$file" dump_data output /dev/null dont_ask || protected=1 | |
# not protected so just encrypt | |
if [ $protected -eq 0 ] | |
then | |
pdftk "$file" output "${file/.pdf/}_protected.pdf" user_pw PASS | |
mv "$file" "$file.old" | |
mv "${file/.pdf/}_protected.pdf" "$file" | |
echo "SUCCESS: $file is now protected"; | |
# has password so try to change it | |
else | |
pdftk "$file" input_pw OLDPASS dump_data output /dev/null dont_ask || passwordworks=0 | |
# password works, so change it | |
if [ $passwordworks -eq 1 ] | |
then | |
pdftk "$file" input_pw OLDPASS output "${file/.pdf/}_new.pdf" user_pw PASS | |
mv "$file" "$file.old" | |
mv "${file/.pdf/}_new.pdf" "$file" | |
echo "SUCCESS: $file password is now changed"; | |
else | |
echo "WARNING: $file password does not work"; | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment