CLI script to rearrange pdf pages for printing book signatures and foldable zines
Go to file
2025-06-19 08:41:04 +02:00
install.sh change name from pdf2book to pdf2zine 2025-06-19 08:41:04 +02:00
LICENSE Initial commit 2025-06-09 15:59:47 +02:00
pdf2zine.py change name from pdf2book to pdf2zine 2025-06-19 08:41:04 +02:00
README.md change name from pdf2book to pdf2zine 2025-06-19 08:41:04 +02:00

pdf2zine

CLI script to rearrange pdf pages for printing book signatures and foldable zines

Install pdf2zine in Linux or macOS

Dependencies:

  • bash (mostly already pre-installed)
    • check with bash --version
  • python3 (mostly already pre-installed)
    • check with python3 --version
  • venv (might be pre-installed)
    • check with python3 -m venv --help
  • git(might be pre-installed)
    • check with git --version

Installation script

use the installation script

# create temporary directory
TMPDIR=$(mktemp -d)
# change into temporary dir
pushd $TMPDIR
# clone pdf2zine source code
git clone https://git.wlankabel.at/onipa/pdf2zine.git 
# change into pdf2zine directory 
pushd pdf2zine
# show help message of install script
bash install.sh -h 
# execute interactive install script
bash install.sh
# change to previous folder
popd
popd 
# remove temporary folder
rm -rf $TMPDIR 

install manually

#!/bin/bash
PREFIX="$HOME/.local"
LIBDIR=$PREFIX/lib
BINDIR=$PREFIX/bin
SRCDIR=$LIBDIR/pdf2zine.git
mkdir -p $LIBDIR $BINDIR
git clone https://git.wlankabel.at/onipa/pdf2zine.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/pdf2zine.py $@
deactivate
'''> $BINDIR/pdf2zine
chmod +x $BINDIR/pdf2zine
echo "you might need to restart your shell"

Similar Tools


pdf2zine.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