Created
May 13, 2022 03:44
-
-
Save kou1okada/bda90632a06a8a56ad8bb0857b7aa852 to your computer and use it in GitHub Desktop.
pdfdroppw.sh - Drop password from PDF file.
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
#!/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