One minute
Bulk PDF password remover
I was tired to put in my password everytime I opened an ecrypted PDF. So I spent 10x more time to automate it. Get the code here.
The script will read the password from password.txt
and will try to decrypt all PDFs in the current folder, copying them to the bkp
folder before, so that if something goes wrong, you are safe. You’ll need to install qpdf
.
#!/bin/bash
# (C) 2022 Massimo Girondi - CC BY-NC-SA 4.0
PASSWD=$(cat password.txt)
remove_pass() {
FILE=$1
if ! [[ $FILE =~ "NOPASSWD" ]]; then
echo "Working on ${FILE}"
DIR=$(dirname "$FILE")
NEW_NAME_BKP=bkp/${FILE}
NEW_NAME="${FILE%.*}_NOPASSWD.pdf"
mkdir -p bkp/${DIR}
mv "$FILE" "${NEW_NAME_BKP}"
qpdf --password=${PASSWD} --decrypt "${NEW_NAME_BKP}" "${NEW_NAME}"
fi
}
while IFS= read -rd $'\0' file; do
remove_pass "$file"
done < <(find . -iname "*.pdf" -not -path "./bkp/*" -print0)