You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
743 B

#!/bin/bash
usage(){
echo "Usage: $(basename "$0") <PAGE|[START]-[END]> <FILE.pdf> [FOLDER|PREFIX]"
}
[[ $# -lt 2 ]] && usage && exit 2
PAGE=$1
PDF=$2
DEST=${3:-.}
[[ ! -f "$PDF" ]] && echo "FAILURE: File <$PDF> not found!" && exit 3
file -bi "$PDF" | grep -q "application/pdf"
[[ $? -ne 0 ]] && echo "FAILURE: File <$PDF> not detected as a valid application/pdf document!" && exit 3
if [[ -d $DEST ]]; then
DEST="$DEST/extract"
fi
if [[ "$PAGE" == *-* ]]; then
START=$(echo "$PAGE" | cut -d '-' -f1)
START=${START:-1}
PAGINATION="-f $START"
END=$(echo "$PAGE" | cut -d '-' -f2)
if [[ ! -z $END ]]; then
PAGINATION="$PAGINATION -l $END"
fi
else
PAGINATION="-f $PAGE -l $PAGE"
fi
pdftoppm -jpeg $PAGINATION "$PDF" "$DEST"