summaryrefslogtreecommitdiffstats
path: root/pdfmerge
blob: 26db6f17d1a9ffcb47f979fcd67de47dafd51785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
# merge multiple pdfs into one

args=$(($# - 1))

infiles=(${@:1:args})
outfile=${!#}

if [[ $# = 0 ]] || [[ $args = 0 ]]; then
	echo "usage: ${0##*/} input.pdf [input2.pdf ..] output.pdf"
	exit 0
fi

if [[ -e $outfile ]]; then
	printf "Error: Output file '%s' already exists!\n" "$outfile" >&2
	exit 1
fi

gs -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$outfile" -sDEVICE=pdfwrite "${infiles[@]}"