Last active
November 9, 2024 07:24
-
-
Save Kurukshetran/92d0e782538e4ec4f4e2f1aeb2fbce16 to your computer and use it in GitHub Desktop.
How to Decrypt a PDF File on Mac: Remove Password from PDF Files on macOS
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 | |
#https://becomegeeks.com/blog/how-to-decrypt-a-pdf-file-on-mac-remove-password-from-pdf-files-on-macos/ | |
PASSWORD="" | |
INPUT_DIR="" | |
OUTPUT_DIR="" | |
while [[ "$#" -gt 0 ]]; do | |
case "$1" in | |
-password=*) PASSWORD="${1#*=}"; shift ;; | |
-inputDir=*) INPUT_DIR="${1#*=}"; shift ;; | |
-outputDir=*) OUTPUT_DIR="${1#*=}"; shift ;; | |
*) | |
echo "Unknown option: $1" | |
echo "Usage: $0 -password=<password> -inputDir=<input_directory> -outputDir=<output_directory>" | |
exit 1 | |
;; | |
esac | |
done | |
if [[ -z "$PASSWORD" || -z "$INPUT_DIR" || -z "$OUTPUT_DIR" ]]; then | |
echo "Missing required arguments." | |
echo "Usage: $0 -password=<password> -inputDir=<input_directory> -outputDir=<output_directory>" | |
exit 1 | |
fi | |
mkdir -p "$OUTPUT_DIR" | |
for file in "$INPUT_DIR"/*.pdf; do | |
filename=$(basename "$file") | |
qpdf --password="$PASSWORD" --decrypt "$file" "$OUTPUT_DIR/${filename%.pdf}_decrypted.pdf" | |
echo "Decrypted $filename and saved as ${filename%.pdf}_decrypted.pdf in $OUTPUT_DIR." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more here