Skip to content

Instantly share code, notes, and snippets.

@konstantingoretzki
Last active October 10, 2019 13:49
Show Gist options
  • Select an option

  • Save konstantingoretzki/246e5f41ae353429792506fc3704f984 to your computer and use it in GitHub Desktop.

Select an option

Save konstantingoretzki/246e5f41ae353429792506fc3704f984 to your computer and use it in GitHub Desktop.
multiDecrypt - decrypt those password protected pdfs
#!/bin/bash
# multiDecrypt - decrypt those password protected pdfs
# Usage: ./multiDecrypt <path> <password>
# Dependency: qpdf
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
if [ "$#" -ne 2 ]; then
echo "multiDecrypt - decrypt those password protected pdfs."
echo "Usage: ./multiDecrypt <path> <password>"
exit
fi
folderPath=$1
password=$2
files=$(ls $folderPath | grep .pdf)
for currentFile in $files
do
echo $currentFile
originalFile=$folderPath/$currentFile
tempFile=$folderPath${currentFile}.old
mv "$originalFile" "$tempFile"
qpdf --decrypt --password=$password "$tempFile" "$originalFile"
done
echo "Do you want to remove the old (encrypted) pdf files? (y/n)"
read removeOldFiles
if [ $removeOldFiles == "y" ] || [ $removeOldFiles == "Y" ]
then
rm ${folderPath}/*.pdf.old
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment