... | ... |
@@ -0,0 +1,32 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+pdf="$1" |
|
4 |
+size=$(pdfinfo "$pdf" | awk '/^Page size:/{ |
|
5 |
+ a = $3 |
|
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" |
|
13 |
+}') |
|
14 |
+pages=$(pdfinfo "$pdf" | awk '/Pages:/{print $2}') |
|
15 |
+test $pages -ne 4 -o -z "$size" && exit |
|
16 |
+ |
|
17 |
+recto=$(mktemp -d /dev/shm/XXXXXXXX) |
|
18 |
+verso=$(mktemp -d /dev/shm/XXXXXXXX) |
|
19 |
+output=$(mktemp --dry-run /dev/shm/XXXXXXXX.pdf) |
|
20 |
+ |
|
21 |
+if test $size = "a3"; then |
|
22 |
+ size="a4" |
|
23 |
+ gs -o $output -sDEVICE=pdfwrite -sPAPERSIZE=$size -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.6 "$pdf" |
|
24 |
+else |
|
25 |
+ cp "$pdf" $output |
|
26 |
+fi |
|
27 |
+ |
|
28 |
+booksize="a$((${size//[^45]}-1))" |
|
29 |
+pdfjam --paper ${booksize}paper --nup 2x1 --landscape --outfile $recto "$output" 1 "$output" 4 |
|
30 |
+pdfjam --paper ${booksize}paper --nup 2x1 --landscape --outfile $verso "$output" 2 "$output" 3 |
|
31 |
+pdftk A=$(find $recto -name "*pdf") B=$(find $verso -name "*pdf") cat A B output "${pdf%/*}/livret-${pdf##*/}" |
|
32 |
+rm -fr $recto $verso $output |
... | ... |
@@ -0,0 +1,32 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+pdf="$1" |
|
4 |
+size=$(pdfinfo "$pdf" | awk '/^Page size:/{ |
|
5 |
+ a = $3 |
|
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" |
|
13 |
+}') |
|
14 |
+pages=$(pdfinfo "$pdf" | awk '/Pages:/{print $2}') |
|
15 |
+output=$(mktemp --dry-run /dev/shm/XXXXXXXX.pdf) |
|
16 |
+recto=$(mktemp --directory /dev/shm/XXXXXXXX) |
|
17 |
+verso=$(mktemp --directory /dev/shm/XXXXXXXX) |
|
18 |
+ |
|
19 |
+if test "${size,,}" != "a5"; then |
|
20 |
+ gs -o $output -sDEVICE=pdfwrite -sPAPERSIZE=a5 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.6 "$pdf" |
|
21 |
+else |
|
22 |
+ cp "$pdf" $output |
|
23 |
+fi |
|
24 |
+pdfjam --paper a4paper --nup '2x1' --landscape --outfile $recto -- "$output" 1 "$output" 1 |
|
25 |
+if test $pages -eq 2; then |
|
26 |
+ pdfjam --paper a4paper --nup '2x1' --landscape --outfile $verso -- "$output" 2 "$output" 2 |
|
27 |
+ pdftk A=$(find $recto -name "*pdf") B=$(find $verso -name "*pdf") cat A B output "$output" |
|
28 |
+else |
|
29 |
+ mv $(find $recto -name "*pdf") $output |
|
30 |
+fi |
|
31 |
+mv $output "${pdf%/*}/massicotable-${pdf##*/}" |
|
32 |
+rm -fr $recto $verso $output |