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

3 years ago
  1. #!/bin/bash
  2. usage(){
  3. echo "Usage: $(basename "$0") <PAGE|[START]-[END]> <FILE.pdf> [FOLDER|PREFIX]"
  4. }
  5. [[ $# -lt 2 ]] && usage && exit 2
  6. PAGE=$1
  7. PDF=$2
  8. DEST=${3:-.}
  9. [[ ! -f "$PDF" ]] && echo "FAILURE: File <$PDF> not found!" && exit 3
  10. file -bi "$PDF" | grep -q "application/pdf"
  11. [[ $? -ne 0 ]] && echo "FAILURE: File <$PDF> not detected as a valid application/pdf document!" && exit 3
  12. if [[ -d $DEST ]]; then
  13. DEST="$DEST/extract"
  14. fi
  15. if [[ "$PAGE" == *-* ]]; then
  16. START=$(echo "$PAGE" | cut -d '-' -f1)
  17. START=${START:-1}
  18. PAGINATION="-f $START"
  19. END=$(echo "$PAGE" | cut -d '-' -f2)
  20. if [[ ! -z $END ]]; then
  21. PAGINATION="$PAGINATION -l $END"
  22. fi
  23. else
  24. PAGINATION="-f $PAGE -l $PAGE"
  25. fi
  26. pdftoppm -jpeg $PAGINATION "$PDF" "$DEST"