# Is it possible to draw a nonprinting box around text, as in the hyperref package?

I would like to be able to draw a box that shows up on in the PDF but does not print, just like the boxes around links that are made using the hyperref package.

I would like to put a minipage environment with multiple paragraphs inside the box.

-

Here's a solution using the pdfcomment package that Martin mentioned.

Upsides:

• doesn't change the cursor to the hand pointer when pointing at the text.

Downsides:

• will most likely only work with Adobe Reader (doesn't work with GhostView and Sumatra)
• you have to find the coordinates for the rectangle manually ("To avoid the method ’trail [sic] and error’ you can load the PDF file with the Ghostscript viewer, which is capable of showing the cursor position in it’s status line.", pdfcomment documentation)
• will or will not print the box depending on the user's setting in the print window; "print document" (doesn't print box) or "print document and markup" (prints box).
• changes the cursor when pointing at the box/border; box is clickable and becomes "selected" when clicked

As for the coordinates:

You can use the option line for defining the coordinates of lines in certain PDF annotations, e. g. in the form {x1 y1 x2 y2}. The origin is in the bottom left page corner. The given numbers will be interpreted as Postscript points (LaTeX unit: bp (big points)), as usual in PDF documents.

\documentclass[a4paper]{article}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{pdfcomment}

\begin{document}
\lipsum[1]

\pdflinecomment[type=polyline,lineend={/None},% = line with >2 "corners", no arrowhead
line={120 720 120 570 480 570 480 720 120 720},% adapt to your document
]{}

\end{document}


-

The border is a PDF annotation and as I saw in the hyperref code part of the hyperlink. Adding it without a link is seems to be not possible using existing LaTeX packages. The related pdfcomments package also provides some annotations but also no border only AFAIK. It might be possible using some direct PDF code using \pdfliteral, but you would need to know the PDF commands for this.

However you can add the border by placing it in a \hyperref or \href, but both do not allow paragraphs as content and generate a very tight border. You could use the v0.5 or higher of the adjustbox package (relative new) to box the minipage first which avoids the paragraph issue, add a margin if wanted and feed it to a \hyperref which e.g. simply points to the current page. The border color can be configured as described in the hyperref manual.

\documentclass{article}

\usepackage{hyperref}

\newenvironment{hborderbox}[1]{%
}{%
}

\usepackage{lipsum}
\begin{document}

\begin{hborderbox}{.5\textwidth}
\lipsum[1]\par\lipsum[2]
\end{hborderbox}

\end{document}


-

it needs \endgraf instead of \par

\documentclass{article}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage{blindtext}
\newcommand\TBox[1]{\href{http://tug.org}{%
\tabular{c}\begin{minipage}{0.75\linewidth}\rule{0pt}{3ex}%
#1\rule[-1ex]{0pt}{0ex}\end{minipage}\endtabular}}

\begin{document}

\TBox{\blindtext \endgraf\blindtext}

\end{document}


-
simple and elegant. – Marco Daniel Aug 29 '11 at 20:34
This doesn't work with normal paragraphs. Paragraph ended before \href@split was complete – Martin Scharrer Aug 29 '11 at 20:48