Last active
October 21, 2019 20:57
-
-
Save crunchywelch/722e2f119aec69bb2a42b86de84a8e56 to your computer and use it in GitHub Desktop.
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 | |
# execute this in the same directory that the report you wish to modify resides | |
command -v pdftk >/dev/null 2>&1 || { echo >&2 "pdftk not installed, aborting."; exit 1; } | |
command -v convert >/dev/null 2>&1 || { echo >&2 "convert not installed, aborting."; exit 1; } | |
command -v jpegoptim >/dev/null 2>&1 || { echo >&2 "jpegoptim not installed, aborting."; exit 1; } | |
rm *final*.pdf | |
echo "please select file to convert:" | |
select FILENAME in *pdf; | |
do | |
echo "processing: $FILENAME" | |
echo "enter number of pages to strip:" | |
read STRIP | |
let "STRIP=STRIP+1" | |
PAGETOTAL=`pdftk $FILENAME dump_data | grep NumberOfPages | sed 's/[^0-9]*//'` | |
echo "stripping pages" | |
pdftk $FILENAME cat $STRIP-$PAGETOTAL output temp.pdf | |
echo "converting to jpg" | |
convert temp.pdf temp.jpg | |
echo "optimizing jpgs" | |
jpegoptim -q --size=40k *jpg | |
COMBINE="convert" | |
FILECOUNT=1 | |
PAGECOUNT=0 | |
for i in `ls -v *jpg`; do | |
let "PAGECOUNT=PAGECOUNT+1" | |
COMBINE="${COMBINE} $i" | |
if (( PAGECOUNT>=50 )); then | |
COMBINEDFILE="${FILENAME::-4}_final_$FILECOUNT.pdf" | |
COMBINE="${COMBINE} $COMBINEDFILE" | |
echo "converting jpgs to pdf" | |
`$COMBINE` | |
COMBINE="convert" | |
let "FILECOUNT=FILECOUNT+1" | |
let PAGECOUNT=0 | |
fi | |
done | |
COMBINEDFILE="${FILENAME::-4}_final_$FILECOUNT.pdf" | |
COMBINE="${COMBINE} $COMBINEDFILE" | |
echo "converting jpgs to pdf" | |
`$COMBINE` | |
echo "cleaning up" | |
rm temp* | |
exit 0 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment