-
Notifications
You must be signed in to change notification settings - Fork 11
/
make_booklet.sh
executable file
·74 lines (67 loc) · 2.36 KB
/
make_booklet.sh
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
# Make booklets
# Usage: sh make_booklet.sh [-r] [FILE]...
# echo -r : rotate odd pages upside down
#
# Recommended trim size: 5.4in x 8in
ROTATE=0 # rotate odd pages upside down
# OPTIONS
DELTA="-0.85in 0in" # space between pages (horizontal vertical)
SCALE="0.72" # absolute page scale
OFFSET="0in 0in" # displace page origins (to_outer to_top)
# PDF META FIELD SED PATTERN
PATTERN="s/^[^:]*:[ \t]*//"
if [ $# -gt 0 ]
then
while [ $# -gt 0 ]
do
if [ "$1" = "-r" ]
then
ROTATE=1
else
TMP="${1%.*}"_tmp.pdf
# META
INFO=$(pdfinfo "$1")
TITLE="$(echo "$INFO" | grep -E "Title" | sed "$PATTERN")"
SUBJECT="$(echo "$INFO" | grep -E "Subject" | sed "$PATTERN")"
KEYWORDS="$(echo "$INFO" | grep -E "Keywords" | sed "$PATTERN")"
AUTHOR="$(echo "$INFO" | grep -E "Author" | sed "$PATTERN")"
pdfjam "$1" -o "$TMP" \
--letterpaper --keepinfo --twoside \
--offset "${OFFSET}"
if [ $ROTATE -gt 0 ]
then
OUTPUT="${1%.*}"_booklet_r.pdf
pdfjam "$TMP" -o "$OUTPUT" \
--a4paper --landscape \
--booklet true --noautoscale true \
--delta "${DELTA}" \
--scale "${SCALE}" \
--pdftitle "$TITLE" \
--pdfsubject "$SUBJECT" \
--pdfkeywords "$KEYWORDS" \
--pdfauthor "$AUTHOR"
else
OUTPUT="${1%.*}"_booklet.pdf
pdfjam "$TMP" -o "$OUTPUT" \
--a4paper --landscape \
--booklet true --noautoscale true \
--delta "${DELTA}" \
--scale "${SCALE}" \
--preamble '\usepackage{everyshi} \makeatletter \EveryShipout{\ifodd\c@page\pdfpageattr{/Rotate 180}\fi} \makeatother' \
--pdftitle "$TITLE" \
--pdfsubject "$SUBJECT" \
--pdfkeywords "$KEYWORDS" \
--pdfauthor "$AUTHOR"
fi
rm "$TMP"
fi
shift
done
else
echo Usage: sh make_booklet.sh [-r] [FILE]...
echo -r : rotate odd pages upside down
echo
echo Recommended trim size: 5.4in x 8in
fi
exit 0