Skip to content

Instantly share code, notes, and snippets.

@VHarisop
Last active September 29, 2021 17:40
Show Gist options
  • Save VHarisop/3e259552cdc2e34942cd7069ae996f17 to your computer and use it in GitHub Desktop.
Save VHarisop/3e259552cdc2e34942cd7069ae996f17 to your computer and use it in GitHub Desktop.
Strip user metadata from PDF by linearizing the output of exiftool.
#!/usr/bin/env bash
function usage() {
cat << 'EOF'
Usage:
linearize_pdf.sh --file <input_file> --output <output_file>.
Arguments:
-f, --file: Input .pdf file to be processed.
-o, --output: Name of output .pdf file.
Notes:
- Assumes `exiftool` and `qpdf` are available and in the user's $PATH.
EOF
}
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-f|--file)
shift
INFILE="$1"
;;
-o|--output)
shift
OUTFILE="$1"
;;
-h|--help)
usage
exit
;;
*)
usage
exit 1
esac
shift
done
exiftool -all= -overwrite_original ${INFILE}
qpdf --linearize ${INFILE} ${OUTFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment