I found a way using GNU Make, pdfinfo (from the poppler package), egrep, sed and bc. The following Makefile will concatenate the files, inserting empty pages where needed so that each subdocument starts on a new paper:
pagecount = $(shell pdfinfo $(1)|egrep "^Pages: *[[:digit:]]+"|sed "s@^Pages: *\([[:digit:]]\+\)@\1@")
odd = $(shell echo $(pagecount)%2|bc|grep 1)
filled = $(1) $(if $(call odd,$(1)),emptypage.pdf)
whole.pdf: 1.pdf 2.pdf 3.pdf 4.pdf 5.pdf 6.pdf 7.pdf 8.pdf 9.pdf
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$@ -dBATCH $(foreach x,$^,$(call filled,$x)) || rm -f $@
The following command is useful for concatenating PDF-files:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=out.pdf -dBATCH a.pdf b.pdf
But I need to modify this so that each subdocument starts on a new paper. This means that if a subdocument has an odd number of pages, an empty page must be inserted after it. Has anyone succeeded with this?
This is wonderful!
I am so amazed that a group of individuals could get together and produce such a useful piece of work -- and then just give it away! Your Unix system is definitely not complete until it has the latest version of GhostScript.
Don't forget that if you use any recent version of RedHat, your copy of GhostScript is probably out of date.
A diskless or systemless environment for client machines.
A non-graphical Java project management component.