-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_note_space
More file actions
222 lines (182 loc) · 4.56 KB
/
create_note_space
File metadata and controls
222 lines (182 loc) · 4.56 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
# preparing standard dimensions and values
directory=`pwd` #current directory
file=false
stdout=false
outputfile=false
acd=false
mcp=false
offset=true
acd_trim="2cm 0cm -10cm 0cm"
acd_offset='-10.5cm 1.5cm'
mcp_trim='0cm 0cm -8cm 0cm'
mcp_offset='-8cm 0cm'
trimleft="2cm"
trimbottom="0cm"
trimright="-10cm"
trimtop="0cm"
offset_l_r="-10.5cmcm"
offset_t_b="1.5cm"
# Call getopt to validate the provided input
options=$(getopt -a -n options -o abtf:o: --long acd,mcp,trim,left:,right:,bottom:,top:,olr:,otb:,file:,out: -- "$@")
[ $? -eq 0 ] || {
echo "Incorrect options provided"
exit 1
}
eval set -- "$options"
while true; do
case "$1" in
-a | --acd)
acd=true
;;
--mcp | -b)
mcp=true
;;
--trim | -t)
offset=false
;;
--file | -f)
shift; # The arg is next in position args
ARG=$1
if [ -z ${ARG+x} ]; then
echo "--file needs a /path/to/file.pdf parameter"
exit 1
fi
# extract name and path and create the full path
fullpath="`realpath \"$ARG\"`"
filebase=`basename "${fullpath}" .pdf`
filedir=`dirname "${fullpath}"`
stdout="${filedir}/${filebase}_notes.pdf"
file=$fullpath
# check if input file exists
if [ ! -f "${file}" ]; then echo "file does not exist: ${file}"; exit 1; fi
pdf=${file: -4}
# check if file is pdf
if [[ ! "$pdf" = ".pdf" ]]; then echo "file needs to be a pdf: ${file}"; exit 1; fi
#create output file name based on input file name, put in same directory as file
filebase=`basename "${file}" .pdf`
filedir=`dirname "${file}"`
;;
--out | -o)
shift;
ARG=$1
# check if parameter is given
if [[ -z ${ARG+x} ]]; then
echo "--out needs a /path/to/output.pdf parameter"
exit 1
fi
# extract filename and path, create full output path
fullpath="`realpath \"$ARG\"`"
filebase=`basename "${fullpath}" .pdf`
filedir=`dirname "${fullpath}"`
stdout="${filedir}/${filebase}.pdf"
outputfile=$fullpath
#check if path can be created
rm "${outputfile}";
if mkdir "${outputfile}"; then
rmdir "${outputfile}"
else
echo "outputfile not creatable. No such file or directory";
fi
;;
--left)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--left needs a \"Xcm\" parameter"
exit 1
else
trimleft=$ARG
fi
;;
--right)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--right needs a \"Xcm\" parameter"
exit 1
else
trimright=$ARG
fi
;;
--bottom)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--bottom needs a \"Xcm\" parameter"
exit 1
else
trimbottom=$ARG
fi
;;
--top)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--top needs a \"Xcm\" parameter"
exit 1
else
trimtop=$ARG
fi
;;
--olr)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--olr needs a \"Xcm\" parameter"
exit 1
else
offset_l_r=$ARG
fi
;;
--otb)
shift;
ARG=$1
if [[ -z ${ARG+x} ]]; then
echo "--otb needs a \"Xcm\" parameter"
exit 1
else
offset_t_b=$ARG
fi
;;
--)
shift
break
;;
*)
echo "Unexpected option: $1 - this should not happen."
;;
esac
shift
done
# check argument integrity
if ( $acp ) && ( $mcp ); then
echo "--acd and --mcp cannot be set together"
exit 1;
fi
if ! [[ "$file" ]]; then
echo "no file given. quit"
exit 1;
fi
# determine values to be used
if ( $acp ); then
loc_trim=$acd_trim;
loc_offset=$acd_offset;
elif ( $mcp ); then
loc_trim=$mcp_trim;
loc_offset=$mcp_offset;
else
loc_trim="${trimleft} ${trimbottom} ${trimright} ${trimltop}"
loc_offset="${offset_l_r} ${offset_t_b}";
fi
# determine outputfile
if [[ $outputfile ]]; then
loc_out=$outputfile;
else
loc_out=$stdout;
fi
if ( $trim ); then
pdfjam --papersize '{1920px,1080px}' --trim "${loc_trim}" "${file}" -o "${loc_out}"
else
pdfjam --papersize '{1920px,1080px}' --offset "${loc_offset}" "${file}" -o "${loc_out}"
fi