Created
April 20, 2023 14:09
-
-
Save Zeta611/17205c02ac0080cd6810a75665d8e433 to your computer and use it in GitHub Desktop.
[Decrypt PDFs] #automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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