Skip to content

Instantly share code, notes, and snippets.

@sithel
Last active February 13, 2019 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sithel/9ef7d09e20c888859d5ba8d78ad834f5 to your computer and use it in GitHub Desktop.
Save sithel/9ef7d09e20c888859d5ba8d78ad834f5 to your computer and use it in GitHub Desktop.
Extremely crude script that takes a PDF, slices & dices, and produces a 2x2 grid of pages laid out for binding (foldable)
#!/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 / 16))
REMAINDER=$(($PAGE_COUNT % 16))
BLANKS=$((16-$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)) * 16))
sig_file_name="output_small/temp_sig_$i.pdf"
temp_cmd="pdfjam --nup 2x2 $FLIPPED_FILE_NAME '$(($i+1)),$(($i+16))' $TEMP_FILE_NAME '$(($i+4)),$(($i+13))' $FLIPPED_FILE_NAME '$(($i+15)),$(($i+2))' $TEMP_FILE_NAME '$(($i+14)),$(($i+3))' $FLIPPED_FILE_NAME '$(($i+5)),$(($i+12))' $TEMP_FILE_NAME '$(($i+8)),$(($i+9))' $FLIPPED_FILE_NAME '$(($i+11)),$(($i+6))' $TEMP_FILE_NAME '$(($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