ReorderPDF1342.sh

RĂ©mi G., 05/31/2014 07:22 pm

Download (662 Bytes)

 
1
#!/usr/bin/sh
2
file=original54.pdf;
3
newfile=$(basename $file .pdf)-2.pdf;
4
tmpfile=$(mktemp --suffix=.pdf);
5
blankfile=$(mktemp --suffix=.pdf);
6
cp -f $file $newfile;
7
numberofpages=`pdftk $file dump_data | grep "NumberOfPages" | sed 's:.*\([0-9][0-9*]\).*:\1:'`;
8
echo "" | ps2pdf -sPAPERSIZE=a4 - $blankfile;
9
while (( $numberofpages % 4 != 0 ));
10
do 
11
  ((numberofpages++));
12
  pdftk A=$newfile B=$blankfile cat A B output $tmpfile;
13
  cp -f $tmpfile $newfile;
14
done;
15
neworder=`
16
for ((  a=1, b=3, c=4, d=2 ;
17
        a <=numberofpages ;
18
        ((a+=4)), ((b+=4)), ((c+=4)), ((d+=4))
19
    ));
20
do
21
echo -n "$a $b $c $d ";
22
done`;
23
pdftk $tmpfile cat $neworder output $newfile;