Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Created May 13, 2022 03:44
Show Gist options
  • Save kou1okada/bda90632a06a8a56ad8bb0857b7aa852 to your computer and use it in GitHub Desktop.
Save kou1okada/bda90632a06a8a56ad8bb0857b7aa852 to your computer and use it in GitHub Desktop.
pdfdroppw.sh - Drop password from PDF file.
#!/usr/bin/env bash
function usage ()
{
cat <<-EOD
Usage: ${0##*/} [options] <pdffile>...
Drop password from PDF file.
Output:
\${@%.*}_nopw.pdf
Environment variables:
\$OPT_PASSWORD : password
Options:
-p, --password <password>
EOD
}
function pdfdroppw () # <pdffile>...
{
local i
for i; do
qpdf --password="${OPT_PASSWORD}" --decrypt "$1" "${1%.*}_nopw.pdf"
done
}
args=()
while (( 0 < $# )); do
case "$1" in
-p|--password)
OPT_PASSWORD="$2"
shift 2
;;
-*)
echo "Error: unknown option: $1"
exit 1
;;
*)
args+=( "$1" )
shift
;;
esac
done
set -- "${args[@]}"
if (( $# <= 0 )); then
usage
exit
fi
pdfdroppw "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment