Skip to content

Instantly share code, notes, and snippets.

@mw866
Last active December 27, 2021 05:50
Show Gist options
  • Save mw866/71c72cd4b51c06c9fcddf2003cf84234 to your computer and use it in GitHub Desktop.
Save mw866/71c72cd4b51c06c9fcddf2003cf84234 to your computer and use it in GitHub Desktop.
decrypt #pdf
# Decrypt all pdf files in the current folder (./) and replace the encrypted files with the decrypted ones
# Prerequisites:
# a. password.txt to be placed in the current folder.
# b. qpdf to be installed.
# Paste it to your ~/.zshrc file.
decrypt(){
if [[ -z $1 ]]
then
DIR="$(pwd)"
else
if [[ -d $1 ]]
then
DIR=$1
else
echo "Directory does not exist"
return 1
fi
fi
echo "Set directory to $DIR"
for file in $DIR/*.pdf
do
qpdf --password="$(<$DIR/password.txt)" --decrypt "$file" "$file.tmp"
rm "$file"
echo "Removed old file: $file"
mv "$file.tmp" "$file"
echo "Renamed new file: $file"
done;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment