impagina: Added documentation and a --help argument

removeproofs
Francesco Minnocci 2 years ago
parent e245525dd5
commit 57dd43cc46
Signed by: BachoSeven
GPG Key ID: 2BE4AB7FDAD828A4

@ -1,27 +1,59 @@
#!/bin/sh #!/bin/sh
# Initialize variables usage() {
input="$1" _name="$(basename "$0")"
inputMul4="/tmp/${input%.pdf}-Mul4.pdf" cat << EOF
outputImpaginato="${input%.pdf}-Impaginato.pdf" Utilizzo: ${_name} [nomePDF]
empty="/tmp/empty.pdf"
n="$(pdftk "$input" dump_data | grep NumberOfPages | cut -d' ' -f2)" Esempi:
# Add empty pages ${_name} MeccanicaRazionale.pdf
echo .bp | groff -T pdf > "$empty"
Per bug contattare f.minnocci@studenti.unipi.it
pdftk F="$input" E="$empty" cat F1-$n $(for x in $(seq 1 $((4-n%4))); do printf 'E1 '; done) output "$inputMul4" I ringraziamenti per l'idea originale vanno a http://poisson.phc.dm.unipi.it/~dilillo
EOF
# Generate alternating page ranges exit $1
n=$((n+(4-n%4))) }
range=
k=1 main() {
while [ "$k" -lt $((n/2)) ]; do # Initialize variables
range="$range$k $((n/2+k)) $((n/2+k+1)) $((k+1)) " input="$(realpath "$1")"
k=$((k+2)) basename="$(basename "$1")"
done inputMul4="/tmp/${basename%.pdf}-Mul4.pdf"
outputImpaginato="${basename%.pdf}-Impaginato.pdf"
# Output final pdf empty="/tmp/empty.pdf"
pdftk "$inputMul4" cat $range output "$outputImpaginato" echo "$input $basename $inputMul4 $outputImpaginato" > ~/log
n="$(pdftk "$input" dump_data | grep NumberOfPages | cut -d' ' -f2)"
rm "$empty" "$inputMul4"
# Add empty pages
echo .bp | groff -T pdf > "$empty"
pdftk F="$input" E="$empty" cat F1-$n $(for x in $(seq 1 $((4-n%4))); do printf 'E1 '; done) output "$inputMul4"
# Generate alternating page ranges
n=$((n+(4-n%4)))
range=
k=1
while [ "$k" -lt $((n/2)) ]; do
range="$range$k $((n/2+k)) $((n/2+k+1)) $((k+1)) "
k=$((k+2))
done
# Output final pdf
pdftk "$inputMul4" cat $range output "$outputImpaginato"
rm "$empty" "$inputMul4"
}
if [ -z "$1" ] ; then
printf "Non hai specificato nessun file...\n\n" && usage 1
else
case "$1" in
-h|--help)
usage 0 ;;
-*)
error "Opzione invalida: $1" ;;
*)
main "$@" ;;
esac
fi

Loading…
Cancel
Save