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