print_compact.sh 555 Bytes
Newer Older
Radek Hušek's avatar
Radek Hušek committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash

COPIES="${1:-1}"
PDF="`xxd -p`"
PAGES=`xxd -p -r <<<"$PDF" | pdfinfo - | sed -nre 's/Pages:\s*(.*)/\1/p'`

if (( PAGES <= 2)); then
  : $(( COPIES = (COPIES + 1) / 2 ))
fi

xxd -p -r <<<"$PDF" |
case $PAGES in
  1) pdfjam --nup 2x1 --landscape --doublepagestwistodd\* true -o /dev/stdout /dev/stdin 1,'{}';;
  2) pdfjam --nup 2x1 --landscape --doublepagestwistodd\* true -o /dev/stdout /dev/stdin 1,2;;
  *) pdfbook -o /dev/stdout /dev/stdin;;
Radek Hušek's avatar
bump    
Radek Hušek committed
16
esac | pdfjam --landscape -o /dev/stdout /dev/stdin `python -c "print(','.join(['-']*$COPIES))"`
Radek Hušek's avatar
Radek Hušek committed
17