[Tex/LaTex] Automatically increase PDF page height

paper-sizepdf

I'd like to emulate HTML's infinite page height using LaTeX/XeTeX, i.e. have the PDF pages grow higher until a manual \newpage is issued.

This could be emulated by setting a very large page height and using pdfcrop on the output (or just setting the page height manually), but I'd like a pure TeX variant and if possible support for footnotes etc at the bottom of the cropped page.

Best Answer

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}