[pdftex] producing a5 booklets from a4

Andreas Matthias amat at kabsi.at
Sun Jun 1 17:13:37 CEST 2003


Heiko Oberdiek wrote:

> On Wed, Oct 09, 2002 at 03:30:11PM +0000, Michael Chapman wrote:
> 
>> I am probably missing something very basic, but is their a method that will 
>> convert BOOK.pdf to PAGE_1.pdf, PAGE_2.pdf, ...... , PAGE_N-1.pdf, 
>> PAGE_N.pdf ?
> 
> This can be easily done by pdfTeX:

Especially when using the \write18 feature, the splitting
can be done with one call to pdflatex:

   pdflatex -shell-escape "\def\pdffile{xyz.pdf} \input split"

%%% begin %%% split.tex %%% begin %%%
\documentclass[a4paper]{article}
\begin{document}
\makeatletter
\pdfximage{\pdffile}
\filename at parse\pdffile
\count@=0
\newwrite\pgfile
\@whilenum\count@<\pdflastximagepages\do{%
  \def\pgfilenamebase{\filename at base-\the\count@}%
  \def\pgfiletex{\pgfilenamebase.tex}%
  \immediate\openout\pgfile\pgfiletex
  \immediate\write\pgfile{%
    \string\hoffset=-1in\string\voffset=-1in
    \string\nopagenumbers
    \string\pdfximage\space page \the\count@ {\pdffile}%
    \string\pdfrefximage\string\pdflastximage
    \string\end
  }%
  \immediate\closeout\pgfile
  \immediate\write18{pdftex \pgfilenamebase}%
  \immediate\write18{rm \pgfilenamebase.tex \pgfilenamebase.log}%
  \advance\count at 1\relax
}
\end{document}
%%% end %%% split.tex %%% end %%%


A shell script can simplify things a bit. Call the script
with the filename of the PDF as its argument:

   pdfsplit xyz.pdf

### begin ### pdfsplit ### begin ###
if test $# -ne 1; then
   echo 'usage: pdfsplit filename'
   exit 1
fi
if test ! -f $1; then
   echo "File $1 not found."
   exit 1
fi
pdflatex -shell-escape "\def\pdffile{$1} \input split"
### end ### pdfsplit ### end ###


Ciao
Andreas



More information about the pdftex mailing list