7

I am trying to put the word "hello" on every page of a pdf file using pdfpages. The following code works, but the frame around "hello" disappears. I tried it on a one blank page pdf file (called "letter.pdf" in the same directory). The first page has an unboxed "hello", but the next page (output in an ordinary way, without the pdfpages callback) works just fine.

\documentclass{minimal}
  \usepackage[final]{pdfpages}
\begin{document}
  % page 1 (no frame around hello)
  \newcommand{\eachpage}{\framebox[1in][l]{hello}}
  \includepdf[pages=-,pagecommand={\eachpage}]{letter.pdf}
  % page 2 (frame works)
  \framebox[1in][l]{hello}
\end{document}
7

The package pdfpages always draws a frame around the included page; but the default is not showing it, which is obtained by setting \fboxrule to zero. Since the addition of pagecommands happens during PDF inclusion, a \framebox will inherit this setting. Note that pdfpages also sets \fboxsep to zero.

Solution:

\newlength{\defaultfboxrule}
\newlength{\defaultfboxsep}
\AtBeginDocument{% Remember the values
  \setlength{\defaultfboxrule}{\fboxrule}%
  \setlength{\defaultfboxsep}{\fboxsep}%
}
\newcommand{\normalfboxes}{%
  \setlength{\fboxrule}{\defaultfboxrule}%
  \setlength{\fboxsep}{\defaultfboxsep}%
}

\newcommand{\eachpage}{%
  \begingroup\normalfboxes
  \framebox[1in][l]{hello}%
  \endgroup
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.