Created
July 16, 2019 10:52
-
-
Save aakbar5/cf8b10987f252a5793fef70be271d041 to your computer and use it in GitHub Desktop.
Merge pdf files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script merge all pds found in a folder | |
# Where $1 is folder name | |
FOLDER="$1" | |
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..." | |
ret="$($CMD)" | |
echo "*** $NEW_NAME is ready." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment