[pdftex] producing a5 booklets from a4
Heiko Oberdiek
oberdiek at uni-freiburg.de
Thu Oct 10 18:33:28 CEST 2002
On Thu, Oct 10, 2002 at 02:52:41PM +0200, Andreas Matthias wrote:
> 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 %%%
> [...]
> %%% end %%% split.tex %%% end %%%
Corrected (numbering 1..N, page size) and
hopefully improved version:
%%% begin %%% split.tex %%% begin %%%
\NeedsTeXFormat{LaTeX2e}
\documentclass{minimal}
%%% Unix setup:
\def\qt#1{'#1'}% command line quoting
\def\pdftex{pdftex}% pdfTeX, plain format
\def\delete{rm}% deletion of several files
%%% End of unix setup
\nofiles % no .aux file
\makeatletter
\catcode|=\active
\let|\@backslashchar
% Test of \pdffile
\@ifundefined{pdffile}{%
\PackageError{split}{%
Macro |pdffile need to be defined\MessageBreak
with the file name as contents.%
}{%
Rerun with: pdflatex -shell-escape %
'|def|pdffile{...}|input split'%
}%
\@@end
}{}
% Test for enabled \write18 can be added here (see pdftricks).
% a little file name cleanup
\edef\pdffile{\expandafter\strip at prefix\meaning\pdffile}
% get file name without extension and directory:
\filename at parse\pdffile
\def\pgfilenamebase{\filename at base-\the\count@}
\def\pgfiletex{\pgfilenamebase.tex}
\newwrite\pgfile
\pdfximage{\pdffile}% to get page count
\endlinechar=10 %
%
\count@=0 %
\@whilenum\count@<\pdflastximagepages\do{%
\advance\count@ by 1 %
\typeout{* Processing page \the\count@\space ...}%
\immediate\openout\pgfile\pgfiletex %
\immediate\write\pgfile{%
|pdfhorigin=0pt
|pdfvorigin=0pt
|pdfximage|space page \the\count@{\pdffile}
|setbox0=|hbox{|pdfrefximage|pdflastximage}
|pdfpagewidth=|wd0
|pdfpageheight=|ht0
|shipout\box0
|end
}%
\immediate\closeout\pgfile %
\immediate\write18{\pdftex\space \qt{\pgfilenamebase}}%
\immediate\write18{\delete\space %
\qt{\pgfilenamebase.log} \qt{\pgfilenamebase.tex}}%
}%
\@@end
%%% end %%% split.tex %%% end %%%
Yours sincerely
Heiko <oberdiek at uni-freiburg.de>
More information about the pdftex
mailing list