Skip to content

Instantly share code, notes, and snippets.

@pascalwhoop
Created November 13, 2016 18:50
Show Gist options
  • Save pascalwhoop/3a85dfd69bbfa8a1e959b6cbea75b72c to your computer and use it in GitHub Desktop.
Save pascalwhoop/3a85dfd69bbfa8a1e959b6cbea75b72c to your computer and use it in GitHub Desktop.
#!/bin/bash
#requires sejda-console to be in the path as 'sejda'
#https://github.com/torakiki/sejda/releases/download/v2.7/sejda-console-2.7-bin.zip
if [ "$1" == "-h" ]; then
echo "Usage: pass the name of one file in the /in folder as a parameter. put all pdfs in an in/ folder"
exit 0
fi
rm -r out/
mkdir out/
# calculate the pdf sizes
HEIGHT=$(mdls in/$1.pdf | grep PageHeight | perl -pe 's/.*= ([\d]+)\.\d*$/\1/')
WIDTH=$(mdls in/$1.pdf | grep PageWidth | perl -pe 's/.*= ([\d]+)\.\d*$/\1/')
echo "starting the calculations"
echo "height:$HEIGHT"
echo "width:$WIDTH"
MWIDTH=$(($WIDTH/2))
MHEIGHT=$(($HEIGHT/2))
echo "middle points: $MWIDTH and $MHEIGHT"
echo "starting sejda"
sejda crop --cropAreas \
"[$MHEIGHT:0][$HEIGHT:$MWIDTH]"\
"[$MHEIGHT:$MWIDTH][$HEIGHT:$WIDTH]"\
"[0:0][$MHEIGHT:$MWIDTH]"\
"[0:$MWIDTH][$MHEIGHT:$WIDTH]"\
--files "`pwd`/in/*.pdf" --output "`pwd`/out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment