Advertisement
opexxx

shrinkpdf.sh

Mar 30th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. # copied from http://www.tatome.de/bliki/doku.php?id=projects:shrinkpdf
  3.  
  4. if [ $# -lt 2 ] || [ $# -gt 3 ]; then
  5. echo usage: shrinkpdf \<filename\> \<resolution\> \[\<output\>\]
  6. exit
  7. fi
  8. if [ ! -e "$1" ]; then
  9. echo "$1" does not exist. Exiting.
  10. exit
  11. fi
  12. if [ $# = 3 ]; then
  13. NEWNAME=$3
  14. else
  15. NEWNAME=`basename $1 .pdf`_shrinked.pdf
  16. fi
  17. if [ "$1 " = "$NEWNAME " ]; then
  18. echo Input and output are identical. Won\'t overwrite---exiting.
  19. exit
  20. fi
  21. if [ -e "$NEWNAME" ]; then
  22. echo "$NEWNAME" exists. Delete? \(y/n\)
  23. read ANS
  24. if [ "$ANS " = "y " ]; then
  25. rm "$NEWNAME"
  26. else
  27. exit
  28. fi
  29. fi
  30. gs -q -dNOPAUSE -dBATCH -dSAFER \
  31. -sDEVICE=pdfwrite \
  32. -dCompatibilityLevel=1.3 \
  33. -dPDFSETTINGS=/screen \
  34. -dEmbedAllFonts=true \
  35. -dSubsetFonts=true \
  36. -dColorImageDownsampleType=/Bicubic \
  37. -dColorImageResolution=$2 \
  38. -dGrayImageDownsampleType=/Bicubic \
  39. -dGrayImageResolution=$2 \
  40. -dMonoImageDownsampleType=/Bicubic \
  41. -dMonoImageResolution=$2 \
  42. -sOutputFile="$NEWNAME" \
  43. "$1"
  44. echo $1: $((`wc -c "$1" | cut -d \ -f 1` / 1024 )) kb
  45. echo $NEWNAME: $((`wc -c "$NEWNAME" | cut -d \ -f 1` / 1024 )) kb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement