Merge PDF files

Merge pdf files placed in a folder:

# This script merge all pds found in a folder
# Where $1 is folder name
FILE_COUNT="$(ls $FOLDER/*.pdf | wc -l)"
NEW_NAME="merged-pdfs-$FILE_COUNT$(cat /dev/urandom | tr -dc '0-9a-zA-Z' | fold -w 16 | head -n 1).pdf"
CMD="gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$NEW_NAME"
# Get all files and append to command
for file in "$FOLDER"/*.pdf; do CMD="$CMD $file"; done
echo "Folder: $1"
echo "File Count: $FILE_COUNT"
echo "Pdf: $NEW_NAME"
# echo "Cmd: $CMD"
echo ""
echo "Merge in progress…"
echo "*** $NEW_NAME is ready."

view raw
Merge pdf files
hosted with ❤ by GitHub