scripts / massicot /
Newer Older
32 lines | 1.283kb
ajout de scripts pour impres...
Sébastien Marque authored on 2020-01-17
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