-
Notifications
You must be signed in to change notification settings - Fork 2
/
catpdf
executable file
·37 lines (29 loc) · 1.34 KB
/
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
33
34
35
36
#!/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
# versions:
# cmd="gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=\"$out\""
# cmd="gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=\"$out\""
# cmd="gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dEmbedAllFonts=true -dSubsetFonts=false -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -sOutputFile=\"$out\""
cmd="gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dEmbedAllFonts=true -dSubsetFonts=false -dPDFSETTINGS=/prepress -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 "$@"