-
Notifications
You must be signed in to change notification settings - Fork 2
/
catpdf
executable file
·33 lines (25 loc) · 867 Bytes
/
catpdf
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
#!/bin/bash
set -e
# to concatenate pdf files: catpdf input1 input2 .. inputN output
# usage: catpdf *pdf output.pdf
#function catpdf() {
#local args=($*) -- does not handle quotes.
#local narg=${#args[@]}
#local out=${args[$narg-1]}
narg=$#
out=${!narg}
# avoid overwriting by mistake
if [ -f "$out" ]
then
echo "Output: '$out' already exists. First delete existing output file."
return 1
fi
cmd="gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=\"$out\""
for (( i = 1 ; i < $narg; i++ ))
do
cmd="$cmd \"${!i}\"" # add \"...\" to support filenames with spaces
done
echo $cmd
eval $cmd # use eval to parse quotes properly (see more here: https://stackoverflow.com/questions/411495/build-argument-lists-containing-whitespace)
#}
#catpdf "$@"