Last active
December 27, 2021 05:50
-
-
Save mw866/71c72cd4b51c06c9fcddf2003cf84234 to your computer and use it in GitHub Desktop.
decrypt #pdf
This file contains 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
# 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