Last active
October 10, 2019 13:49
-
-
Save konstantingoretzki/246e5f41ae353429792506fc3704f984 to your computer and use it in GitHub Desktop.
multiDecrypt - decrypt those password protected pdfs
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
| #!/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