Created
February 13, 2019 03:18
-
-
Save sithel/d8905a57fe48db25ebec5d736810936e to your computer and use it in GitHub Desktop.
Extremely crude script that takes a PDF, slices & dices, and produces a 4x4 grid of pages laid out for binding (to be printed on tabloid paper)
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 | |
clear | |
echo "PDF file name:" | |
read FILE_NAME | |
echo "PDF page count:" | |
read PAGE_COUNT | |
echo "... looking at the following file:" | |
ls -la $FILE_NAME | |
echo | |
SIGS=$(($PAGE_COUNT / 32)) | |
REMAINDER=$(($PAGE_COUNT % 32)) | |
BLANKS=$((32-$REMAINDER)) | |
echo "Checking..." | |
if [ "$REMAINDER" -gt 0 ] | |
then | |
echo "You will have $BLANKS blank page(s) at the end" | |
SIGS=$(($SIGS + 1)) | |
fi | |
echo "There will be $SIGS signatures" | |
if [ -d 'output_small' ] | |
then | |
rm -rf output_small | |
echo "Dumping all old content from the directory 'output_small'" | |
fi | |
mkdir 'output_small' | |
TEMP_FILE_NAME="output_small/temp.pdf" | |
FLIPPED_FILE_NAME="output_small/temp_flipped.pdf" | |
cp $FILE_NAME $TEMP_FILE_NAME | |
pdf180 $FILE_NAME --outfile $FLIPPED_FILE_NAME | |
for sig in `seq 1 $SIGS`; | |
do | |
echo "Signature : $sig of $SIGS" | |
i=$(($(($sig - 1)) * 32)) | |
sig_file_name="output_small/temp_sig_$i.pdf" | |
# temp_cmd="pdfjam --nup 4x4 $FLIPPED_FILE_NAME '1, 16, 17, 32' $TEMP_FILE_NAME '4,13,20,29' $FLIPPED_FILE_NAME '5,12,21,28' $TEMP_FILE_NAME '8,9,24,25' $FLIPPED_FILE_NAME '31, 18, 15,2' $TEMP_FILE_NAME '30,19,14,3' $FLIPPED_FILE_NAME '27,22,11,6' $TEMP_FILE_NAME '26,23,10,7' --outfile $sig_file_name" | |
temp_cmd="pdfjam --nup 4x4 $FLIPPED_FILE_NAME '$(($i+1)),$(($i+16)),$(($i+17)),$(($i+32))' $TEMP_FILE_NAME '$(($i+4)),$(($i+13)),$(($i+20)),$(($i+29))' $FLIPPED_FILE_NAME '$(($i+5)),$(($i+12)),$(($i+21)),$(($i+28))' $TEMP_FILE_NAME '$(($i+8)),$(($i+9)),$(($i+24)),$(($i+25))' $FLIPPED_FILE_NAME '$(($i+31)),$(($i+18)),$(($i+15)),$(($i+2))' $TEMP_FILE_NAME '$(($i+30)),$(($i+19)),$(($i+14)),$(($i+3))' $FLIPPED_FILE_NAME '$(($i+27)),$(($i+22)),$(($i+11)),$(($i+6))' $TEMP_FILE_NAME '$(($i+26)),$(($i+23)),$(($i+10)),$(($i+7))' --outfile $sig_file_name" | |
echo $temp_cmd | |
eval $temp_cmd | |
done | |
exit 0 | |
TEMP_CMD="ls" | |
echo | |
echo "what? '$TEMP_CMD'" | |
eval $TEMP_CMD | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment