CLI script to rearrange pdf pages for printing book signatures and foldable zines
install.sh | ||
LICENSE | ||
pdf2book.py | ||
README.md |
pdf2book
CLI script to rearrange pdf pages for printing book signatures and foldable zines
INSTALL pdf2book in Linux or macOS
Dependencies:
bash
(mostly already installed)- check with
bash --version
- check with
python3
(mostly already installed)- check with
python3 --version
- check with
venv
(might be installed)- check with
python3 -m venv --help
- check with
#!/bin/bash
PREFIX="$HOME/.local"
LIBDIR=$PREFIX/lib
BINDIR=$PREFIX/bin
SRCDIR=$LIBDIR/pdf2book.git
mkdir -p $LIBDIR $BINDIR
git clone https://git.wlankabel.at/onipa/pdf2book.git $SRCDIR
python3 -m venv $SRCDIR/.venv
. $SRCDIR/.venv/bin/activate
pip3 install pypdf
echo -n '''#!/bin/bash
SRCDIR='$SRCDIR'
VENVDIR=$SRCDIR/.venv
. $VENVDIR/bin/activate
python3 $SRCDIR/pdf2book.py $@
deactivate
'''> $BINDIR/pdf2book
chmod +x $BINDIR/pdf2book
echo "you might need to restart your shell"
pdf2book.py
This script takes a pdf and reorders pages for printing simple signatures. One sheets holds 4 pages. The number of sheets per signature can be varied. In the following code snippet the original sequence of pages on a sheet and its changed sequence are shown.
this is how the squence is changed in a 1 sheet per signature setting
._________. ._________. ._________. ._________.
| | | | | | | | | | | |
| 1 | 2 | + | 3 | 4 | -> | 4 | 1 | + | 2 | 3 |
| | | | | | | | | | | |
'---------' '---------' '---------' '---------'
# 1 sheet per signature
s=1: 1,2,3,4 -> 04,01.02,03 i=0
08,05.06,07 i=1
12,09.10,11 i=2
16,13.14,15 i=3
20,17.18,19 i=4
down=(i+1)*4*s
up= (i)*4*s+1
#pages_mod=$(python -c " (int(pages/s)+1)*(pages%s) " )
for i in $(pages%s)
print (down--,up++,up++,down--)
# 2 sheets per signature
s=2: 1,2,3,4,5,6,7,8 -> 08,01.02,07 06,03.04,05 i=0
16,09.10,15 14,11.12,13 i=1
24,17.18,23 22,19.20.21 i=2
down=(i+1)*4*s
up= (i)*4*s+1
for i in range(pages%s):
for count in range(2):
print (down--,up++,up++,down--)
# 3 sheets per signature
s=3: 1,2,3,4,5,6,7,8,9,10,11,12 -> 12,01.02,11 10,03.04,09 08,05.06,07
24,13.14,23 22,15.16,21 20,17.18,19
# 4 sheets per signature
s=4: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -> 16,01.02,15 14,03.04,13 12,05.06,11 10,07.08,09
32,17,18,31 30,19.20.29 28,21.22.27 26,23.24,25
TODO
- alternative names to pdf2book
- write install script
- test in powershell