forked from phc/dm-scripts
impagina: Added documentation and a --help argument
This commit is contained in:
@@ -1,10 +1,28 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
_name="$(basename "$0")"
|
||||||
|
cat << EOF
|
||||||
|
Utilizzo: ${_name} [nomePDF]
|
||||||
|
|
||||||
|
Esempi:
|
||||||
|
|
||||||
|
${_name} MeccanicaRazionale.pdf
|
||||||
|
|
||||||
|
Per bug contattare f.minnocci@studenti.unipi.it
|
||||||
|
I ringraziamenti per l'idea originale vanno a http://poisson.phc.dm.unipi.it/~dilillo
|
||||||
|
EOF
|
||||||
|
exit $1
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
# Initialize variables
|
# Initialize variables
|
||||||
input="$1"
|
input="$(realpath "$1")"
|
||||||
inputMul4="/tmp/${input%.pdf}-Mul4.pdf"
|
basename="$(basename "$1")"
|
||||||
outputImpaginato="${input%.pdf}-Impaginato.pdf"
|
inputMul4="/tmp/${basename%.pdf}-Mul4.pdf"
|
||||||
|
outputImpaginato="${basename%.pdf}-Impaginato.pdf"
|
||||||
empty="/tmp/empty.pdf"
|
empty="/tmp/empty.pdf"
|
||||||
|
echo "$input $basename $inputMul4 $outputImpaginato" > ~/log
|
||||||
n="$(pdftk "$input" dump_data | grep NumberOfPages | cut -d' ' -f2)"
|
n="$(pdftk "$input" dump_data | grep NumberOfPages | cut -d' ' -f2)"
|
||||||
|
|
||||||
# Add empty pages
|
# Add empty pages
|
||||||
@@ -25,3 +43,17 @@ done
|
|||||||
pdftk "$inputMul4" cat $range output "$outputImpaginato"
|
pdftk "$inputMul4" cat $range output "$outputImpaginato"
|
||||||
|
|
||||||
rm "$empty" "$inputMul4"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user