How do I create a PDF document whose height exactly matches the contents?

You could use the standalone class in combination with a minipage of the same width as the text in your main document:

\documentclass{standalone}

\usepackage{lipsum}

\begin{document}

\begin{minipage}{345pt}
\lipsum[2]
\end{minipage}

\end{document}

To find out what the width of the text in your main document is, the showdim package offers the \tenthpt macro:

\documentclass{article}

\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{showdim}

\begin{document}

\tenthpt{\textwidth}

\lipsum[2]

\noindent\includegraphics[width=\textwidth]{document}

\end{document}

enter image description here

(the vertical space between the text and the image might need a bit of adjustment)


Use pdfcrop:

\documentclass{article}

\usepackage{lipsum} % for mock text

\pagestyle{empty} % no page ornaments

\begin{document}

\lipsum[1]

\end{document}

Save this as shortdoc.tex and run

pdflatex shortdoc
pdfcrop shortdoc

This will produce shortdoc-crop.pdf, that you can include with \includegraphics.

Tags:

Pdf

Include

Page