summaryrefslogtreecommitdiff
path: root/localpdf2pdfscreen
blob: 442eb2077755fa718b98be6613f51b8ce99a9f83 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/localpdf2pdfscreen
  4. # Copyright 2008 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localpdf2pdfscreen,v 1.4 2008-03-17 13:07:47 jonas Exp $
  7. #
  8. # Downsize PDF file.
  9. #
  10. # TODO: Use *_lowres.pdf as default outfile
  11. #
  12. set -e
  13. PRG="$(basename "$0")"
  14. # Default options
  15. PDFTOPSOPTS="-paper match"
  16. PS2PDFOPTS="-dPDFSETTINGS=/screen"
  17. showhelp() {
  18. cat <<EOF
  19. Usage: $PRG INFILE [ OUTFILE ] [ pdftops opts ] [ -- ps2pdf opts ]
  20. If missing, OUTFILE is INFILE.pdf (ie. double pdf extension).
  21. Examples:
  22. $PRG newspaper.pdf newspaper_screenready.pdf
  23. EOF
  24. }
  25. exit1() {
  26. echo >&2 "ERROR: $1"
  27. exit 1
  28. }
  29. [ $# -gt 0 ] || exit1 "Input file missing"
  30. infile=
  31. outfile=
  32. pdftopsopts=
  33. pstopdfopts=
  34. while [ $# -gt 0 ]; do
  35. case $1 in
  36. -h|--help)
  37. showhelp
  38. exit 0
  39. ;;
  40. --)
  41. shift
  42. break
  43. ;;
  44. -*)
  45. pdftopsopts="$pdftopsopts $1"
  46. shift
  47. ;;
  48. *)
  49. if [ -z "$infile" ]; then
  50. infile="$1"
  51. elif [ -z "$outfile" ]; then
  52. outfile="$1" ]
  53. else
  54. exit1 "Too many parameters"
  55. fi
  56. shift
  57. ;;
  58. esac
  59. done
  60. ps2pdfopts="$@"
  61. # Use defaults if not overridden
  62. outfile="${outfile:-$infile.pdf}"
  63. pdftopsopts="${pdftopsopts:-$PDFTOPSOPTS}"
  64. ps2pdfopts="${ps2pdfopts:-$PS2PDFOPTS}"
  65. [ ! -e "$outfile" ] || exit1 "Output file already exists"
  66. tmpfile=$(mktemp -t "$PRG.XXXXXXXXXX") || exit 1
  67. pdftops $pdftopsopts "$infile" "$tmpfile" || rm "$tmpfile"
  68. ps2pdf $ps2pdfopts "$tmpfile" "$outfile"
  69. rm "$tmpfile"
  70. exit 0