summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/pdfjam/pdfpun
blob: 2d008ae6d71daf352cff324d6492c51a8f72ffdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
##
##  pdfpun: A shell program to n-up pages of a PDF file with
##          the n-upped pages ordered from right to left
##
##  Author David Firth (http://go.warwick.ac.uk/dfirth)
##
##  This is a simple wrapper for (three runs of) pdfjam, version 2.06
##
##
E_USAGE=64           ##  for a command line usage error
##
for arg
do
    case $arg in
	--batch)
	    printf "pdfpun ERROR: the --batch option is not allowed\n" 1>&2; 
	    exit "$E_USAGE" ;;
        --no-tidy) 
	    n='--no-tidy' ;;
	--quiet | -q)
	    q='-q' ;;
	--checkfiles)
	    c='--checkfiles' ;;
	*) continue ;;
    esac
done
sourceFile="$1" ;
shift ;
##
##  Some (very) minimal checking of the first argument:
##
if test ! -f "$sourceFile" ;
then
    printf "pdfpun ERROR: first argument must be a PDF file\n" ; 
    exit $E_USAGE ;
fi
if test "$sourceFile" = /dev/stdin ;
then
    if tty -s ; then
	printf "pdfpun ERROR: tty is connected to connected to stdin, no PDF file found\n" 
	exit $E_USAGE ;
    fi
fi
##
##  That's all the argument checking!
##
pageSpec="-"         ## the default
case ${1} in
    --* | "") 
	;;
    *)     ## a page spec was given
	pageSpec="$1" ;
	shift ;;
esac
case ${1} in 
    --outfile)
	outFile="$2" ;
        shift; shift ;;
    *) 
	;;
esac
if test -z "$outFile" ; 
then 
    printf "pdfpun ERROR: no output file specified\n" 1>&2 ; 
    exit "$E_USAGE" ;  
fi 
pdfjam --reflect true $n $q $c "$sourceFile" "$pageSpec" -o /dev/stdout | \
  pdfjam --landscape --nup 2x1 "$@" -o /dev/stdout | \
    pdfjam --suffix nup --reflect true --fitpaper true $n $q -o "$outFile"