Pocketmod from PDF using LaTeX
Pocketmod is a great way to convey information. However, converting from an eight page PDF to the nifty single page format is often difficult using online tools, often resulting in a watermarked result or some subpar result.
Fear not! Using a simple script and LaTeX, one can accomplish this. Assuming a *nix or macOS environment with the LaTeX suite installed, the following script can help.
#!/bin/sh
# pdf2pocketmod – script to generate 1-page pocketmod from 8-page pdf.
# Updated by William Moore, 2025 to work differently.# 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=“./pdf2pocketmod”
mkdir “$tmpdir”
cp “$infile” “$tmpdir/in.pdf”
pushd “$tmpdir”# invert pages which need to be inverted
$pdflatex \\batchmode
'\documentclass[letterpaper,portrate]{book}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=1]{in.pdf}
\includepdf[pages=2-3]{in.pdf}
\includepdf[pages=7, angle=180]{in.pdf}
\includepdf[pages=6, angle=180]{in.pdf}
\includepdf[pages=5, angle=180]{in.pdf}
\includepdf[pages=4, angle=180]{in.pdf}
\includepdf[pages=8]{in.pdf}
\end{document}'mv texput.pdf book.pdf
# compose pages into 1-page pocketmode mosaic
$pdflatex \\batchmode
'\documentclass[letterpaper,landscape]{book}
\usepackage{pdfpages}
\usepackage{hyperref}
\hypersetup{
pdfproducer = {pdf2pocketmod}
}
\begin{document}
\includepdf[nup=4x2, pages={8,1,2-7}, trim=0mm 0mm 0mm 0mm]{book.pdf}
\end{document}'
mv texput.pdf “../$outfile”
popd
rm -rf “$tmpdir”
Once made executable, the script is easy. Assuming it is named “pdf2pocketmod.sh”, the execution is:
./pdf2pocketmod.sh in.pdf
This will generate a file in the same path where the script was executed called “in_pocketmod.pdf”. That’s all there is to it.
Happy folding!