# pdf2book CLI script to rearrange pdf pages for printing book signatures and foldable zines ## Install pdf2book in Linux or macOS ### Dependencies: - [`bash`](https://www.gnu.org/software/bash/) (mostly already pre-installed) - check with `bash --version` - [`python3`](https://www.python.org/downloads/) (mostly already pre-installed) - check with `python3 --version` - [`venv`](https://docs.python.org/3/library/venv.html) (might be pre-installed) - check with `python3 -m venv --help` - [`git`](https://git-scm.com/downloads)(might be pre-installed) - check with `git --version` ### Installation script use the installation script ```bash # create temporary directory TMPDIR=$(mktemp -d) # change into temporary dir pushd $TMPDIR # clone pdf2book source code git clone https://git.wlankabel.at/onipa/pdf2book.git # change into pdf2book directory pushd pdf2book # 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 ```bash #!/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