Skip to content

Instantly share code, notes, and snippets.

@MarkusH
Last active May 12, 2024 14:08
Show Gist options
  • Save MarkusH/7ff12f21b940b5c1637d59626b80675e to your computer and use it in GitHub Desktop.
Save MarkusH/7ff12f21b940b5c1637d59626b80675e to your computer and use it in GitHub Desktop.
Ghostscript Tools
#!/usr/bin/bash
set -e
# https://stackoverflow.com/a/70438840
declare -a files=()
declare -a arr=($(echo "$2" | tr "," " "))
# splitting
for i in "${arr[@]}"; do
gs -dBATCH -sDEVICE=pdfwrite -sPageList="$i" -dNOPAUSE -sOutputFile="$i".tmp "$1"
# reordering for combining
files+=("$i.tmp")
done
# combining to combine.pdf
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$3" -dBATCH "${files[@]}"
# removing temporary files
rm "${files[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment