This reverses the order of the pages which are output while \RPtrue is set, and keeps pages in the normal order when \RPfalse is active. References and hyperlinks should work. I use Heiko Oberdiek's atbegshi package to hook into the \shipout primitive (which is responsible for sending pages to the dvi/pdf file): instead of sending the pages out, we store them in \RPbox. Namely, the contents of \RPbox have the form
- Skip of
1 pt
- First page to be reversed.
- Kern of size
<first page number> sp
- Second page to be reversed.
- Kern of size
<second page number> sp
- Etc.
Then in \RPfalse we use \lastkern and \lastbox to retrieve the contents of box registers and ship pages out one by one, with the correct page number in place (this makes sure that references are right). The assignments to \c@page are done locally so that the old value is restored once all pages have been output.
Also, I put a \clearpage in the macros \RPtrue and \RPfalse because I thought that would make more sense, but things shoud work without.
\documentclass{article}
\usepackage{atbegshi}
\newif\ifRP
\newbox\RPbox
\setbox\RPbox\vbox{\vskip1pt}
\makeatletter
\AtBeginShipout{%
\ifRP
\AtBeginShipoutDiscard%
\global\setbox\RPbox\vbox{\unvbox\RPbox
\box\AtBeginShipoutBox\kern\c@page sp}%
\fi
}%
\renewcommand{\RPtrue}{%
\clearpage
\ifRP\RPfalse\fi
\global\let\ifRP\iftrue
}%
\renewcommand{\RPfalse}{%
\clearpage
\global\let\ifRP\iffalse
\setbox\RPbox\vbox{\unvbox\RPbox
\def\protect{\noexpand\protect\noexpand}%
\@whilesw\ifdim0pt=\lastskip\fi
{\c@page\lastkern\unkern\shipout\lastbox}%
}%
}%
\makeatother
% Test document.
\usepackage{lipsum}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{Lipsum 1--50}
\lipsum[1-50]
\RPtrue
\section{Lipsum 51--100}
\lipsum[51-100]
\RPfalse
\section{Lipsum 101--150}
\lipsum[101-150]
\end{document}
pdftksupport/retains the hyperlinks? There is e.g. also thepdfjamscript (based on thepdfpagesLaTeX package) which will remove all hyperlinks. – Martin Scharrer Jun 27 '11 at 13:26