flake: Restructure home/
This commit is contained in:
parent
07268b2730
commit
9389d2661a
5 changed files with 3 additions and 4 deletions
74
home/alex/local/bin/merge-pdf
Executable file
74
home/alex/local/bin/merge-pdf
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p ghostscript -p coreutils
|
||||
#
|
||||
# Local Variables:
|
||||
# mode: sh
|
||||
# End:
|
||||
#
|
||||
|
||||
workdir=
|
||||
keep_workdir=false
|
||||
output=-
|
||||
|
||||
function usage {
|
||||
cat <<EOF
|
||||
usage: merge-pdf [options] files...
|
||||
|
||||
options:
|
||||
-o FILE write result to FILE (default: -)
|
||||
EOF
|
||||
}
|
||||
|
||||
function cleanup {
|
||||
if [ x"${keep_workdir}" != x"true" ]; then
|
||||
if [ -d "${workdir}" ]; then
|
||||
rm -rf "${workdir}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
trap "cleanup" EXIT
|
||||
|
||||
while getopts ":ho:k" o; do
|
||||
case "$o" in
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
o)
|
||||
output="$OPTARG"
|
||||
;;
|
||||
k)
|
||||
keep_workdir=true
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
workdir=$(mktemp -d)
|
||||
|
||||
echo >&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
|
||||
Loading…
Add table
Add a link
Reference in a new issue