Rotate single PDF page when viewing

You can indeed use the pdfpageattr command. You can do it as follows:

\documentclass{article}
\begin{document}
  text

  \pagebreak[4]
  \global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}
  text
\end{document}

This will rotate the second page by 90 degrees. It should be obvious how to get different rotations.


The accepted answer did not work for me, since it rotated all pages in the PDF instead of a single one. I managed to get it to work using the pdflscape package instead, as suggested in this answer:

\usepackage{pdflscape}
...
\begin{landscape}
...
\end{landscape}

I needed this to display figures. Note that, when inside the landscape environment, you must use \linewidth for a figure's width, \textwidth will not work.


A slightly more complete version to the accepted answer would be to create an environment that turns the page back to portrait:

\newenvironment{rotatepage}%
    {\clearpage\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}}%
    {\clearpage\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%

And then \begin{rotatepage} <the content on this page is turned 90°> \end{rotatepage}.


But we can extend this further. We might want to use the features provided by the rotating package. And we might use documents that use different margins for odd and even pages. Then an automated solution that turns the page by 90° or 270° respectively would be nice. An example using KOMA script:

\documentclass[twoside]{scrreprt}
\usepackage{scrextend,rotating}

\makeatletter
\newenvironment{rotatepage}
        {%
            \if@twoside%
                \ifthispageodd{\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}}{%
                \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 270}}%
            \else%
                \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}%
            \fi%
        }%
        {\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%

\makeatother

And then \begin{rotatepage}\begin{sidewaystable} <the content on this page is turned 90°> \end{sidewaystable}\end{rotatepage}


Finally, we can combine rotatepage and the environments provided by the rotating package. If we want to turn pages automatically that use sidewaytable, we can hook the rotatepage environment into sidewaytable with etoolbox. In addition to the code above we would need:

\BeforeBeginEnvironment{sidewaystable}{\begin{rotatepage}}
\AfterEndEnvironment{sidewaystable}{\end{rotatepage}}

Of course, similar adjustments could be made for sidewaysfigure etc.

Tags:

Pdf

Rotating