diff --git a/home/local/bin/merge-pdf b/home/local/bin/merge-pdf index c5b4e62..a2d0de5 100755 --- a/home/local/bin/merge-pdf +++ b/home/local/bin/merge-pdf @@ -1,8 +1,74 @@ #! /usr/bin/env nix-shell -#! nix-shell -i bash -p ghostscript +#! nix-shell -i bash -p ghostscript -p coreutils # # Local Variables: # mode: sh # End: +# -gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=- -dBATCH "$@" +workdir= +keep_workdir=false +output=- + +function usage { + cat <&2 "[INFO] Putting temporary files into ${workdir}" + +files=() +for f; do + fname=$(basename "$f" .pdf) + of="${workdir}/${fname}.ps" + echo >&2 "[PS ] \"${f}\" -> \"${of}\"" + pdf2ps "$f" "${of}" >&/dev/null + files+=("$of") +done + +echo >&2 "[PDF ] combining ${#files[@]} file(s) into ${output}" + +gs -dNOPAUSE -sDEVICE=pdfwrite \ + -dPDFSETTINGS=/prepress \ + -sPAPERSIZE=a4 \ + -sFIXEDMEDIA \ + -sOUTPUTFILE="${output}" \ + -dBATCH \ + "${files[@]}" >&/dev/null