Showing 1 changed files with 17 additions and 9 deletions
+17 -9
massicot
... ...
@@ -4,26 +4,34 @@ pdf="$1"
4 4
 size=$(pdfinfo "$pdf" | awk '/^Page size:/{
5 5
 	a = $3
6 6
 	b = $5
7
-	if (a >= 419  && a <= 421  && b >= 594  && b <= 596 ) print "a5"
8
-	if (a >= 594  && a <= 596  && b >= 419  && b <= 421 ) print "a5"
9
-	if (a >= 594  && a <= 596  && b >= 841  && b <= 843 ) print "a4"
10
-	if (a >= 841  && a <= 843  && b >= 594  && b <= 596 ) print "a4"
11
-	if (a >= 841  && a <= 843  && b >= 1189 && b <= 1191) print "a3"
12
-	if (a >= 1189 && a <= 1191 && b >= 841  && b <= 843 ) print "a3"
7
+	if (a >= 419  && a <= 421  && b >= 594  && b <= 596 ) print "a5 portrait"
8
+	if (a >= 594  && a <= 596  && b >= 419  && b <= 421 ) print "a5 paysage"
9
+	if (a >= 594  && a <= 596  && b >= 841  && b <= 843 ) print "a4 portrait"
10
+	if (a >= 841  && a <= 843  && b >= 594  && b <= 596 ) print "a4 paysage"
11
+	if (a >= 841  && a <= 843  && b >= 1189 && b <= 1191) print "a3 portrait"
12
+	if (a >= 1189 && a <= 1191 && b >= 841  && b <= 843 ) print "a3 paysage"
13 13
 }')
14 14
 pages=$(pdfinfo "$pdf" | awk '/Pages:/{print $2}')
15 15
 output=$(mktemp --dry-run /dev/shm/XXXXXXXX.pdf)
16 16
 recto=$(mktemp --directory /dev/shm/XXXXXXXX)
17 17
 verso=$(mktemp --directory /dev/shm/XXXXXXXX)
18 18
 
19
-if test "${size,,}" != "a5"; then
19
+if test "${size% *}" != "a5"; then
20 20
     gs -o $output -sDEVICE=pdfwrite -sPAPERSIZE=a5 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.6 "$pdf"
21 21
 else
22 22
     cp "$pdf" $output
23 23
 fi
24
-pdfjam --paper a4paper --nup '2x1' --landscape --outfile $recto -- "$output" 1 "$output" 1
24
+if test "${size#* }" = "portrait"; then
25
+    pdfjam --paper a4paper --nup '2x1' --landscape --outfile $recto -- "$output" 1 "$output" 1
26
+else
27
+    pdfjam --paper a4paper --nup '1x2' --no-landscape --outfile $recto -- "$output" 1 "$output" 1
28
+fi
25 29
 if test $pages -eq 2; then
26
-    pdfjam --paper a4paper --nup '2x1' --landscape --outfile $verso -- "$output" 2 "$output" 2
30
+    if test "${size#* }" = "portrait"; then
31
+        pdfjam --paper a4paper --nup '2x1' --landscape --outfile $verso -- "$output" 2 "$output" 2
32
+    else
33
+        pdfjam --paper a4paper --nup '1x2' --no-landscape --outfile $verso -- "$output" 2 "$output" 2
34
+    fi
27 35
     pdftk A=$(find $recto -name "*pdf") B=$(find $verso -name "*pdf") cat A B output "$output"
28 36
 else
29 37
     mv $(find $recto -name "*pdf") $output