Ethan Mick

Decrypt all PDF's in a Directory

I recently had to decrypt a bunch of PDF's. I knew the password, but didn't want to do them one at a time. Luckily, some quick scripting did the trick.

brew update && brew install qpdf

Fire up your favorite text editor (I named the file decrypt.sh):

#!/bin/bash
DECRYPTED_FOLDER="decrypted"
mkdir $DECRYPTED_FOLDER
for f in *.pdf
do
qpdf --decrypt --password="$1" "$f" "$DECRYPTED_FOLDER/$f"
done

Give it some power: chmod +x decrypt.sh

Make sure the script is in the same directory as the PDF's you want to convert. It'll make a new directory called "decrypted" and dump the PDF's into it.

./decrypt.sh pdfPasswordHere

For example:

./decrypt.sh awesomesauce

Enjoy decrypting!

Be the best web developer you can be.

A weekly email on Next.js, React, TypeScript, Tailwind CSS, and web development.

No spam. Unsubscribe any time.