diff options
author | Jonas Smedegaard <dr@jones.dk> | 2008-03-17 12:53:04 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2008-03-17 12:53:04 +0000 |
commit | b85e717cea722198254d13478496b26d85bc641a (patch) | |
tree | 3dee544090dcc97b486f635228a6429a535ece24 /localpdf2pdfscreen | |
parent | 48a658728a36b7e4e2df161c8a1e9195ea730821 (diff) |
Fix and improve option parsing. Add copyright header.
Diffstat (limited to 'localpdf2pdfscreen')
-rwxr-xr-x | localpdf2pdfscreen | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/localpdf2pdfscreen b/localpdf2pdfscreen index 9f5fc0d..3d2095d 100755 --- a/localpdf2pdfscreen +++ b/localpdf2pdfscreen @@ -1,12 +1,26 @@ #!/bin/sh +# +# /usr/local/bin/localpdf2pdfscreen +# Copyright 2008 Jonas Smedegaard <dr@jones.dk> +# +# $Id: localpdf2pdfscreen,v 1.2 2008-03-17 12:53:04 jonas Exp $ +# +# Downsize PDF file. +# +# TODO: Use *_lowres.pdf as default outfile +# set -e -PRG="$0" +PRG="$(basename "$0")" + +# Default options +PDFTOPSOPTS="-paper match" +PS2PDFOPTS="-dPDFSETTINGS=/screen" showhelp() { cat <<EOF -Usage: $PRG INFILE [ OUTFILE ] +Usage: $PRG INFILE [ OUTFILE ] [ pdftops opts ] [ -- ps2pdf opts ] If missing, OUTFILE is INFILE.pdf (ie. double pdf extension). @@ -21,11 +35,35 @@ exit1() { exit 1 } -if [ $# -eq 0 ]; then - showhelp - exit1 "Not enough parameters" -fi +[ $# -gt 0 ] || exit1 "Input file missing" + +pdftopsopts= +pstopdfopts= +while [ $# -gt 0 ]; do + case $1 in + -h|--help) + showhelp + exit 0 + ;; + --) + shift + break + ;; + -*) + pdftopsopts="$pdftopsopts $1" + shift + ;; + *) + pools="$pools $1" + shift + ;; + esac +done +ps2pdfopts="$@" +# Use default options if none provided +[ -n "pdftopsopts" ] || pdftopsopts="$PDFTOPSOPTS" +[ -n "ps2pdfopts" ] || ps2pdfopts="$PS2PDFOPTS" infile="$1" tmpfile=$(mktemp -t "$PRG.XXXXXXXXXX") || exit 1 @@ -33,5 +71,9 @@ outfile="${2:-$infile.pdf}" [ ! -e "$outfile" ] || exit1 "Output file already exists" -pdftops -paper match "$infile" "$tmpfile" -ps2pdf -dPDFSETTINGS=/screen "$tmpfile" "$outfile" +pdftops $pdftopsopts "$infile" "$tmpfile" +ps2pdf $ps2pdfopts "$tmpfile" "$outfile" + +rm "$tmpfile" + +exit 0 |