File poster.sh of Package pdfposter
#!/bin/sh
# A wrapper script to emulate /usr/bin/poster, which is needed for kde to
# enable poster printing.
#
# (C) 2009-2010 jw@suse.de, Novell Inc.
# Released under GPLv2 or GPLv3.
#
# 20090930 - jw@suse.de
# ghostscript-library has /usr/bin/pdf2ps and /usr/bin/ps2pdf
# Requires: pdfposter ghostscript-library xpdf-tools
#
# pdf2ps from ghostscript-library makes ugly fonts.
pdf2ps=/usr/bin/pdftops
ps2pdf=/usr/bin/ps2pdf
pdfposter=/usr/bin/pdfposter
# getopt makes it hard to parse whitespace correctly, allows --long-opts,
# but has no example code in the man-page.
# getopts at least has a useful example in the man-page, but
# makes it impossible to use --gnuish-longhorn-options.
#
# We chose getopts for simplicity, as poster has no --long-opts.
# If you need them, use getopt and follow the arcana in
# http://software.frodo.looijaard.name/getopt/docs/getopt-parse.bash
#
# None of them saves you the long case statement anyhow.
# but at least they support run together short options,
# and automatically trigger the usage by providing -? in case of errors.
# Definitly an unexpectedly small benefit for the arcana of getopts.
outfile=
verbose=
dry_run=
opts=(-O 6)
while getopts vfni:m:p:s:c:w:C:O:P:o: option; do
case $option in
f) printf "manual feed: ignored, not implemented in pdfposter.\n";;
i) printf "input box: ignored, not implemented in pdfposter.\n";;
c) printf "cut margin: ignored, not implemented in pdfposter.\n";;
w) printf "white margin: ignored, not implemented in pdfposter.\n";;
C) printf "Clipping aid: ignored, not implemented in pdfposter.\n";;
P) printf "Page select: ignored, not implemented in pdfposter.\n";;
v) opts[${#opts[@]}]="--verbose"; verbose=1;;
n) opts[${#opts[@]}]="--dry-run"; dry_run=1;;
m) opts[${#opts[@]}]="-m"; opts[${#opts[@]}]="$OPTARG";;
p) opts[${#opts[@]}]="-p"; opts[${#opts[@]}]="$OPTARG";;
s) opts[${#opts[@]}]="-s"; opts[${#opts[@]}]="$OPTARG";;
O) opts[${#opts[@]}]="-O"; opts[${#opts[@]}]="$OPTARG";;
o) outfile="$OPTARG";;
M) $pdfposter --help-media-names; exit;;
?) printf "Usage: %s: [options] [infile]\n" $0 1>&2
cat << EOF 1>&2
valid options are:
-v: be verbose
-n: dry run.
-M: List available media and distance names and exit.
-m<box>: media paper size. Default A4
-p<box>: output poster size. Default same as -m
-s<number>: linear scale factor for poster
-o<file>: output redirection to named file
-O<number>: content overlap. Default 6
compatibility options (accepted but ignored) are:
-f: ask manual feed on plotting/printing device
-i<box>: specify input image size
-c<margin>: horizontal and vertical cutmargin
-w<margin>: horizontal and vertical additional white margin
-C<number>: clipping facilities (grid label and cutmarks)
bit 1 (value = 1): cutmark lines
bit 2 (value = 2): cutmark arrow heads
bit 3 (value = 4): grid label
-P<pages>: comma-separated list of tile pages to print
At least one of -s -p -m is mandatory, and don't give both -s and -p
<box> is like 'A4', '3x3letter', '10x25cm', '200x200+10,10p'
<margin> is either a simple <box> or <number>%. Page lists are comma-
separated, each element being a single page or a page range.
(ex: 1,2-5,8,10-34)
Defaults are: '-mA4', '-c5%', '-i<box>' read from input file.
and output written to stdout.
EOF
exit 2;;
esac
done
shift $(($OPTIND - 1))
# printf "Remaining arguments are: %s\n" "$*" 1>&2
tmp_i=/tmp/poster_in_$$.pdf
tmp_o=/tmp/poster_out_$$.pdf
infile="$1"
test -z "$infile" && infile=-
if [ -z "$outfile" -a -t 1 ]; then
echo "stdout is a tty. Redirect with '>' or use -o outfile.ps"
exit 0
fi
printf "dry_run=$dry_run verbose=$verbose\n" 1>&2;
test $verbose && echo "$ps2pdf '$infile' $tmp_i" 1>&2
test $dry_run || $ps2pdf "$infile" $tmp_i
test $verbose && echo "$pdfposter $opts $tmp_i $tmp_o" 1>&2
test $dry_run || $pdfposter "${opts[@]}" $tmp_i $tmp_o
test $verbose && echo "$pdf2ps $tmp_o $outfile" 1>&2
test $dry_run || $pdf2ps $tmp_o $outfile
test $dry_run || rm -f $tmp_o $tmp_i