# Automatically increase PDF page height

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.

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}

• Enclosing the content in a minipage takes care of the footnotes (or would that be more restrictive than necessary?) – pascal May 27 '11 at 21:43
• @pascal: If you need footnotes you can add minipages. However they number footnotes differently. Floats won't work either. – Martin Scharrer May 27 '11 at 22:25
• This works very well --- except for floats, as you mention. I tried working around it with \begin{figure}[h]... but that still doesn't work because of "Not in outer par mode". Any idea of getting around that, and getting an image with a caption? – Supernormal Sep 2 '16 at 13:48
• @Supernormal: The point of a float is that if floats over multiple pages to a place where it fits according to professional typesetting rules. Most users have issues understanding this at first. If you simply want to add a caption then use alternatives. The topic is further described in these posts: How to influence the position of float environments like figure and table in LaTeX? , Keeping tables/figures close to where they are mentioned – Martin Scharrer Sep 9 '16 at 8:08
• @Supernormal: Also check out my standalone package which I created since I wrote this post. It is either based on preview or uses its own technique, depending on the used options. It can also be used to turn floats into non-floats automatically (but I'm not sure if I published that feature already). – Martin Scharrer Sep 9 '16 at 8:10

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

• Wow. I really have to look into ConTeXt... – pascal May 27 '11 at 21:46
• IMO nicer then the solution I've posted (from 10 years ago) – topskip May 28 '11 at 5:39

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.