Skip to content

Instantly share code, notes, and snippets.

@robotanarchy
Created January 22, 2015 16:38
Show Gist options
  • Save robotanarchy/f1c75603efdc252a0445 to your computer and use it in GitHub Desktop.
Save robotanarchy/f1c75603efdc252a0445 to your computer and use it in GitHub Desktop.
qpdf wrapper for easy pdf decryption
#!/bin/bash
input="$1"
output="_decrypted_$input"
if [[ $# != 2 ]] || [[ ! -f "$input" ]]; then
echo "Syntax: $(basename $0) INPUTFILE.PDF PASSWORD"
exit 1
fi
echo "Removing password..."
qpdf --password="$2" --decrypt "$input" "$output"
# something went wrong, eg. wrong password!
[[ ! -f "$output" ]] && exit 1
# switcheroo!
rm "$input"
mv "$output" "$input"
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment