-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfmerge
executable file
·52 lines (43 loc) · 990 Bytes
/
pdfmerge
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
#!/bin/bash
# src: http://stackoverflow.com/a/19358402/4419816
USAGE="Usage: $(basename "${0}") <INFILE(S)> <OUTFILE>"
main()
{
if [[ ${#} -lt 2 ]]
then
echo "${USAGE}"
return 1
fi
infiles=("${@}")
n=$((${#infiles[@]}-1))
outfile="${infiles[$n]}"
unset infiles[${n}]
assert_file "${infiles[@]}" || return ${?}
if [ -f "${outfile}" ]
then
echo "error: '${outfile}' already exists!" >&2
return 1
fi
echo "PDFMERGE: ${infiles[@]} -> ${outfile}"
gs -q \
-dBATCH \
-dNOPAUSE \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-sOutputFile="${outfile}" \
"${infiles[@]}" >/dev/null 2>&1
if [ ${?} -ne 0 ]
then
echo "Errors occurred during merging!" >&2
return 1
fi
}
command -v assert_file >/dev/null || {
assert_file()
{
local path="${1}"
[ -f "${path}" ] || return 1
return 0
}
}
main "${@}"