-
Notifications
You must be signed in to change notification settings - Fork 0
/
perStampaTorre.sh
executable file
·139 lines (122 loc) · 3.59 KB
/
perStampaTorre.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -e
#read output file name
function outputFileName(){
echo "digit output file name:"
read -e output
}
#read input files names
function inputFileName(){
echo "digit input file names:"
read -e inputs
}
#show the help
function showHelp(){
echo "
This is a script for help printing operation in laboratories of unipd.
It allows to concatenate multiple PDF files and put 1, 2 or 4 slides per page.
usage: ./perStampaTorre.sh [-h] [<args>]
where:
-h show this help
<args> could be formatted as:
1. inputFile1.pdf ... inputFileN.pdf outputFileName.pdf
2. inputFile1.pdf ... inputFileN.pdf
in this case during the script the name of output file is asked
if no args are passed to the script the name of input and output files are asked during the script
CAUTION! input file name cannot contain spaces
The number of slides per pages is asked during the script. The possibilities are:
1 -> means 1 slide per page
2 -> means 2 slides per pages, with landscape orientation
|----------|----------|
| | |
| S1 | S2 |
| | |
|----------|----------|
4 -> means 4 slides per pages, with landscape orientation
|----------|----------|
| S1 | S2 |
|----------|----------|
| S3 | S4 |
|----------|----------|
"
}
# check if help is wanted or script is runned
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
showHelp
else
#check if there is one or two arguments
echo $1
if [ -z "$1" ] || [ -z "$2" ]
then
#if there is no arguments
if [ -z "$1" ]
then
inputFileName
outputFileName
else
#there is only one argument -> assumed that output file name is missing
inputs=$1
outputFileName
fi
else
inputs=""
output=""
counter=0
outputNumber=$(($#-1))
for var in "$@"
do
if [ $counter -eq $outputNumber ]
then
output=$var
else
inputs=$inputs" "$var
fi
counter=$(($counter+1))
done
fi
echo "insert number of slides for pages (1-2-4):"
read number
if [ $number -eq 1 ] || [ -z "$number" ]
then
# 1 slide per page -> only concatenation is performed
pdftk $inputs cat output $output
elif [ $number -eq 2 ]; then
# 2 slides per page
pdftk $inputs cat output $output
temp="temp"$output
pdfnup -o $temp $output
rm $output
pdftk A=$temp shuffle AoddEast AevenWest output $output
rm $temp
elif [ $number -eq 4 ]; then
# 3 slides per page
temp="temp"$output
pdftk $inputs cat output $temp
temp2="temp"$temp
pdfjam $temp --nup 2x2 --landscape --outfile $temp2
pdftk A=$temp2 shuffle AoddEast AevenWest output $output
rm $temp
rm $temp2
else
# if number different from 1,2 and 4 or a string is inserted
echo "Number not supported yet"
fi
echo "Number of page for splitting (Default no, 0 = no):"
read number
if [ -z "$number" ] || [ $number -eq 0 ]
then
echo "No split performed"
else
counter=1
outputname=0
numberofpage=`pdftk $output dump_data | grep NumberOfPages | sed 's/[^0-9]*//'`
while [ $(($counter+$number-1)) -lt $numberofpage ]; do
progress=$(($counter+$number-1))
pdftk $output cat $counter-$progress output "$outputname-$output"
let counter=counter+number
let outputname=outputname+1
done
pdftk $output cat $counter-$numberofpage output "$outputname-$output"
fi
fi