Removing Passwords from Multiple PDF Files
Okay, so I found myself in a pickel where I had around 15-20 password-protected PDF files sitting on my laptop. And guess what? Manually removing passwords from each one? Can’t be bothered!
My brain immediately went into “Let’s script this shit up” mode.
This is how I came up with the below script to remove password from all required pdf files.
I would definitely need this in future, hence sharing here for future reference.
First install qpdf
sudo apt install -y qpdf
Actual Script :
#!/bin/bash
# Check if qpdf is installed
if ! [ -x "$(command -v qpdf)" ]; then
echo 'Error: qpdf is not installed.' >&2
exit 1
fi
pdfpassword="your_pdf_password"
# Decrypt pdf files
for file in $(find . -name "*Australia_Document*.pdf" | sed 's/.\///g'); do
echo "Starting Decrypting pdf for : $file"
# Rename files to your liking using sed
newfile=$(echo $file | sed 's/Australia_//g')
echo "Decrypting $file ----> $newfile"
qpdf --password=$pdfpassword --decrypt $file $newfile
echo -e "Decryption Complete for : $file \n\n"
done