Last active
July 24, 2021 22:42
-
-
Save meniluca/85e4a30ae886ae7d0fbccd86d520a43d to your computer and use it in GitHub Desktop.
simple script to make printable booklets for DIY book bindings
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 | |
set -u | |
# requires pdfinfo pdfseparate pdfunite pdfbook2 | |
PDF_INPUT=$1 | |
PDF_OUTPUT=$2 | |
echo "converting $PDF_INPUT" | |
echo "writing output file: $PDF_OUTPUT" | |
PAGES=`pdfinfo $PDF_INPUT | grep -i pages | awk '{print $2}'` | |
echo "contains $PAGES pages" | |
GROUP_BY=16 | |
echo "grouping by $GROUP_BY pages per batch" | |
loops=$((PAGES/GROUP_BY)) | |
PARTS_LIST="" | |
for i in $(seq 0 $loops) | |
do | |
echo "i (batch number): $i" | |
f=$((i*GROUP_BY+1)) | |
if [ $f -gt $PAGES ]; then | |
echo "Nothing left to process" | |
break; | |
fi | |
echo "f (starting page for batch number $i): $f" | |
l=$(((i+1)*GROUP_BY)) | |
echo "l (last page for batch number $i): $l" | |
pdfseparate -f $f -l $l $PDF_INPUT output-%d.pdf | |
echo "pdfunite: " $(ls -1v output*) | |
pdfunite $(ls -1v output*) part_$i.pdf | |
rm output-* | |
pdfbook2 --no-crop --short-edge part_$i.pdf | |
echo "Created: part_$i-book.pdf" | |
rm part_$i.pdf | |
PARTS_LIST=$PARTS_LIST" part_$i-book.pdf" | |
done | |
echo "pdfunite " $PARTS_LIST | |
echo "writing $PDF_OUTPUT" | |
pdfunite $PARTS_LIST $PDF_OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment