blob: 2fd90a1d8473d25660c59a24109397aa015c3127 (
plain)
- #!/bin/sh
- #
- # /usr/local/bin/localpdf2pdfscreen
- # Copyright 2008 Jonas Smedegaard <dr@jones.dk>
- #
- # $Id: localpdf2pdfscreen,v 1.3 2008-03-17 13:06:44 jonas Exp $
- #
- # Downsize PDF file.
- #
- # TODO: Use *_lowres.pdf as default outfile
- #
- set -e
- PRG="$(basename "$0")"
- # Default options
- PDFTOPSOPTS="-paper match"
- PS2PDFOPTS="-dPDFSETTINGS=/screen"
- showhelp() {
- cat <<EOF
- Usage: $PRG INFILE [ OUTFILE ] [ pdftops opts ] [ -- ps2pdf opts ]
- If missing, OUTFILE is INFILE.pdf (ie. double pdf extension).
- Examples:
- $PRG newspaper.pdf newspaper_screenready.pdf
- EOF
- }
- exit1() {
- echo >&2 "ERROR: $1"
- exit 1
- }
- [ $# -gt 0 ] || exit1 "Input file missing"
- infile=
- outfile=
- pdftopsopts=
- pstopdfopts=
- while [ $# -gt 0 ]; do
- case $1 in
- -h|--help)
- showhelp
- exit 0
- ;;
- --)
- shift
- break
- ;;
- -*)
- pdftopsopts="$pdftopsopts $1"
- shift
- ;;
- *)
- if [ -z "$infile" ]; then
- infile="$1"
- elif [ -z "$outfile" ]: then
- outfile="$1" ]
- else
- exit1 "Too many parameters"
- fi
- shift
- ;;
- esac
- done
- ps2pdfopts="$@"
- # Use defaults if not overridden
- outfile="${outfile:-$infile.pdf}"
- pdftopsopts="${pdftopsopts:-$PDFTOPSOPTS}"
- ps2pdfopts="${ps2pdfopts:-$PS2PDFOPTS}"
- [ ! -e "$outfile" ] || exit1 "Output file already exists"
- tmpfile=$(mktemp -t "$PRG.XXXXXXXXXX") || exit 1
- pdftops $pdftopsopts "$infile" "$tmpfile" || rm "$tmpfile"
- ps2pdf $ps2pdfopts "$tmpfile" "$outfile"
- rm "$tmpfile"
- exit 0
|