Automatically increase PDF page height

You could use the preview package for this. It's basically the "pure (La)TeX variant of pdfcrop" you are looking for. You need to set the text height to \maxdimen e.g. using geometry and wrap every page in \begin{preview} ... \end{preview}. To do this simply have a \begin{preview} after \begin{document}, a \end{preview} before \end{document} and define a \newpage variant as \end{preview}\begin{preview}. You will loose some of the border which can be readded using the \PreviewBorder macro. However, AFAIK this doesn't support header and footer.


Here now some example code. Apparently preview already takes care to suppress automatic page breaks and the modification of the text height is not required.

\documentclass{article}

\usepackage[active,tightpage]{preview}

\renewcommand{\PreviewBorder}{1in}

\newcommand{\Newpage}{\end{preview}\begin{preview}}

\usepackage{lipsum}
\begin{document}
\begin{preview}
\lipsum
\Newpage
\lipsum[1]
\Newpage
\lipsum[1-30]
\Newpage
\lipsum[4-22]
\end{preview}
\end{document}

Another ConTeXt solution. This takes care of footnotes, but you need to mark the start and stop of the page.

\definestartstop[infinite]
                [before={\startTEXpage
                         \setupfootnotedefinition[location=joinedup]%
                        \startlocalfootnotes},
                 after={\placelocalfootnotes
                         \stoplocalfootnotes
                         \stopTEXpage}]

\setupTEXpage[width=\textwidth, offset=2mm]

which can then be used as

\starttext
\startinfinite
\section {Some section}
\input knuth \footnote{A random footnote}
\input ward
\stopinfinite
\stoptext

Thanks for the replies, I'm using Martin's solution, from my class file:

\iftrue
  \usepackage[active,tightpage,psfixbb]{preview}
  \renewcommand{\PreviewBorder}{1cm}

  \newenvironment{stretchpage}%
    {\begin{preview}\begin{minipage}{\hsize}}%
    {\end{minipage}\end{preview}}
  \AtBeginDocument{\begin{stretchpage}}
  \AtEndDocument{\end{stretchpage}}

  \newcommand{\@@newpage}{\end{stretchpage}\begin{stretchpage}}

  \let\@real@section\section
  \renewcommand{\section}{\@@newpage\@real@section}
\fi

This works for me, if I would want to print the document, I can just disable the block.

Tags:

Pdf

Paper Size