Created
October 11, 2020 18:07
-
-
Save etairi/942ac1e8b982afe17e598c0b8c0985aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Global constants | |
CLEAR='\033[0m' | |
RED='\033[0;31m' | |
# Helper usage function | |
function usage() { | |
if [ -n "$1" ]; then | |
echo -e "${RED}ERROR: $1${CLEAR}\n"; | |
fi | |
echo "Usage: $0 [-f files]" | |
echo " -f, --files The files to transform" | |
echo "" | |
echo "Optional:" | |
echo " -t, --trim The trim value. If it is not specified defaults" | |
echo " to LNCS trim value '3.2cm 3.2cm 3.2cm 3.2cm'" | |
echo "" | |
echo "Example: $0 --files 'test1.pdf test2.pdf' --trim '1cm 2cm 1cm 2cm'" | |
exit 1 | |
} | |
# Parse parameteres | |
while [[ "$#" > 0 ]]; do case $1 in | |
-f|--files) FILES="$2";shift;shift;; | |
-t|--trim) TRIM="$2";shift;shift;; | |
*) usage "Unknown parameter passed: $1"; shift;shift;; | |
esac; done | |
# Verify parameters | |
if [ -z "$FILES" ]; then usage "Files are not set"; fi; | |
if [ -z "$TRIM" ]; then TRIM='3.2cm 3.2cm 3.2cm 3.2cm'; fi; | |
for file in $FILES; do | |
pdfjam "$file" --trim "$TRIM" --clip true --outfile tmp.pdf; | |
pdfjam tmp.pdf --batch --nup 2x1 --suffix 2up --landscape --outfile "$file"; | |
rm -f tmp.pdf | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment