Skip to content

Instantly share code, notes, and snippets.

@Zeta611
Created April 20, 2023 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zeta611/17205c02ac0080cd6810a75665d8e433 to your computer and use it in GitHub Desktop.
Save Zeta611/17205c02ac0080cd6810a75665d8e433 to your computer and use it in GitHub Desktop.
[Decrypt PDFs] #automation
#!/bin/bash
# Check if qpdf is installed
if ! command -v qpdf >/dev/null; then
echo "qpdf not found. Please install qpdf and try again."
exit 1
fi
# Check if enough arguments are supplied
if [ "$#" -lt 3 ]; then
echo "Usage: $0 password input_folder output_folder"
exit 1
fi
# Get the password, input folder, and output folder
password="$1"
input_folder="$2"
output_folder="$3"
# Create the output folder if it doesn't exist
mkdir -p "$output_folder"
# Decrypt each PDF file in the input folder
for file in "$input_folder"/*.pdf; do
file_name=$(basename "$file")
output_file="$output_folder/${file_name%.pdf}_unlocked.pdf"
qpdf --password="$password" --decrypt "$file" "$output_file"
echo "Processed $file_name"
done
echo "All files have been processed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment