Rotate single PDF page when viewing

I got a Latex document which renders fine, some content is rotated using the turn environment from the rotate package. Everything works like it should.

Except: It know that it is possible to display a single page in a pdf in another orientation. The document viewer then rotates this page when viewing. This would help the readers of my document to read the turned text.

How is this possible? Perhaps somehow using the pdfpageattr command?

Again: I do not to want to rotate the content, I just want to tell the PDF-Reader that it should rotate the page when displaying.

-
You could have a look at how pdflscape does it. –  Roelof Spijker Jan 10 '12 at 19:53
I already tried that, but I can not read Latex Module Code so I do not understand what happens there. –  theomega Jan 10 '12 at 20:04
So you want a series of regular (portrait) pages, and then a rotated (landscape) page, and then some more regular (portrait) pages, right? Is it possible to completely separate the content on the landscape page? That is, is it (say) a page-sized table or figure, or does the landscape page form part of the regular text flow, but you just want it rotated? –  Werner Jan 10 '12 at 20:29

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.

-
If I change the important line with the folowing: \global\pdfpageattr\expandafter{/Rotate 90}, it also work. Why? –  Azoun Jan 10 '12 at 21:03
then the current attributes won't be saved. Which is usually not a problem, unless you have some other attributes set already. –  Roelof Spijker Jan 11 '12 at 0:09
Thanks, exacttly what I was searching for. Now I'm running into other problems, but that will be another question here. –  theomega Jan 11 '12 at 13:37
Could you please show how to do this for a single page, i.e. how to change it back to the default after one page. This would improve the answer very much. I would recommend to use afterpage. –  Martin Scharrer Apr 24 '12 at 10:32
@MartinScharrer It's been a while and your suggestion hasn't been included in this answer. I landed on this question wanting to know how to do exactly what you describe! Would you be able to expand on your suggestion with an edit, or a separate answer? –  joran Sep 12 '12 at 18:29

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.

-
Welcome to TeX.SX! –  Claudio Fiandrino Oct 30 '13 at 13:37

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

\newenvironment{rotatepage}%
{\pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}}%
{\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.

-