pdf2pocketmod



A pocketmod is a 8-page booklet obtained by folding a single sheet. How? This video shows how to do it. Here is a simple script to convert an 8-page pdf document into a pocketmod-foldable sheet, it is a modified version of a script by Rick Holbert.

#!/bin/sh

# pdf2pocketmod - script to generate 1-page pocketmod from 8-page pdf.
# Little Neo, 2011

# very very very inspired by Rick Holbert
# http://weblog.bignerdranch.com/?p=23 (see comments)

# The script works with A4 paper. If you want to use US letter paper, replace the word a4paper with letterpaper.

# use: ./pdf2tinybk foo.pdf
# will generate foo_pocketmod.pdf

# Enjoy!


pdflatex=$(whereis pdflatex|cut -d' ' -f 2)

infile="$1"
outfile="$(basename $infile .pdf)_pocketmod.pdf"

tmpdir="/tmp/$$"

mkdir "$tmpdir"
cp "$infile" "$tmpdir/in.pdf"
cd "$tmpdir"

# invert pages which need to be inverted

$pdflatex \\batchmode \
'\documentclass[a4paper,portrate]{book}\
\usepackage{pdfpages}\
\begin{document}\
\includepdf[pages=1, angle=180]{in.pdf}\
\includepdf[pages=2-5]{in.pdf}\
\includepdf[pages=6-8, angle=180]{in.pdf}\
\end{document}'

mv book.pdf in.pdf

# compose pages into 1-page pocketmode mosaic

$pdflatex \\batchmode \
'\documentclass[a4paper,landscape]{book}\
\usepackage{pdfpages}\
\usepackage{hyperref}\
\hypersetup{\
pdfproducer = {pdf2pocketmod}\
}\
\begin{document}\
\includepdf[nup=4x2, pages={2-5,1,8-6}, trim=0mm 0mm 0mm 0mm, cut, frame]{in.pdf}\
\end{document}'

mv book.pdf "$OLDPWD/$outfile"

rm -rf "$tmpdir"

Application : the one hundred push ups program.


Little Neo, January 2011


Code

Home