pdf2pocketmod



Un pocketmod est un livret de 8 pages obtenu en pliant une simple feuille. Comment ? Cette vidéo le montre. Voilà un script simple pour convertir un document PDF de huit pages en une feuille pocketmodable, il s'agit d'une version modifiée d'un script de 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 : le programme cent pompes.


Little Neo, janvier 2011


Code

Home