Add remove-pdf-password.sh
authorColin P. Mccabe <colin@cmccabe.xyz>
Thu, 22 Jul 2021 23:28:54 +0000 (16:28 -0700)
committerColin P. Mccabe <colin@cmccabe.xyz>
Thu, 22 Jul 2021 23:28:54 +0000 (16:28 -0700)
remove-pdf-password.sh [new file with mode: 0755]

diff --git a/remove-pdf-password.sh b/remove-pdf-password.sh
new file mode 100755 (executable)
index 0000000..79c8a6e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+die() {
+    echo $@
+    exit 1
+}
+
+[[ $# -eq 1 ]] || die "this script takes exactly one argument: the name of a pdf"
+INPUT=$1
+INPUT_BASE=${INPUT%.pdf}
+[[ -f "${INPUT}" ]] || die "input file ${INPUT} does not exist."
+echo -n Password: 
+read -s PASSWORD
+echo
+exec qpdf -password="${PASSWORD}" -decrypt "${INPUT}" "${INPUT_BASE}.decrypted.pdf"