There is a portrait document in which only the second page have to be made landscape (the document has header and footer made with fancyhdr). To accomplish the portrait to landscape turn I'm using the following:
\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight
Also, I'm using geometry to adjust layout in both modes (portrait and landscape). I'm going fine in maintaining the top and left margins across the modes. But I'm not seeing how to manage right and bottom.
To exemplify: I've tried \geometry{bottom=5cm} but in the landscape mode the footer goes beyond the page. It seems that the 4 lines of code above just cut the paper accordingly but foot stays in the same position (as in portrait mode).
What's the proper way to switch from portrait to landscape maintaining margins?
The following demonstrates what happens, foot disappear in landscape.
\documentclass[10pt,a4paper]{article}
\usepackage[left=3cm, top=5cm, headheight=2cm, height=20cm]{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\begin{document}
\thispagestyle{fancy}
\pagestyle{fancy}
\lipsum[1]
\newpage
\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight
\newgeometry{left=3cm, top=5cm, headheight=2cm}
\fancyhfoffset[L]{0pt}
\lipsum[1]
\restoregeometry
\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth
\lipsum[1]
\end{document}


\newgeometryand\restoregeometry. – Johannes_B Jun 27 '15 at 20:20newgeometry, you should not use the pdf-primitives.geometrywill take care of setting everything right. – Johannes_B Jun 27 '15 at 20:35landscapeenvironment, provided by the lscape package, rotates the contents of the page before the output routine does its job of adding the header and the footer. (The pdflscape package merely adds appropriate instructions for the previewer to also turn the relevant pages on the screen, so that you don’t have to turn your head instead.) Thus, the header and the footer are kept in their usual position, along the shorter edges of the paper. What’s wrong with this? – GuM Jun 27 '15 at 22:21