Skip to content

Instantly share code, notes, and snippets.

@sambatyon
Last active November 9, 2021 16:25
Show Gist options
  • Save sambatyon/5123685 to your computer and use it in GitHub Desktop.
Save sambatyon/5123685 to your computer and use it in GitHub Desktop.
small scripts used to create a full pdf document.
#!/bin/bash
if [[ `uname` =~ MINGW.* ]]; then
GS=gswin64c
else
GS=gs
fi
output=$1
shift
filelist=$@
filelist=$(echo ${filelist[*]} | tr ' ' "\n" | sort)
processed_files=""
for f in $filelist; do
if [ ${f##*.} != pdf ]; then
convert $f ${f%%.*}.pdf
f=${f%%.*}.pdf
fi
processed_files="${processed_files}${f} "
done
filelist=$processed_files
$GS -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$output $filelist
# Alternatively:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=contract.pdf $(ls)
# To split:
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dSAFER -o splitted.%d.pdf contract.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment