# exam/geometry: How to use \iflastpage to change the geometry of the last page?

How to make \iflastpage{\newgeometry{bottom=40mm}}{} work to have a specific bottom offset for only the last page?

\documentclass{exam}
\usepackage[14pt]{extsizes}
\usepackage{lipsum}

\usepackage[bottom=20mm]{geometry}

\newcommand{\myfooter}{\iflastpage{%
{\centering\large End of the Exam}%
\vspace{5pt}}{}
\hrule\vspace{5pt}
Instructors}

\firstpagefooter{}{\myfooter}{}
\runningfooter{}{\myfooter}{}

\iflastpage{\newgeometry{bottom=40mm}}{}

\begin{document}
\lipsum[1-5]
\end{document}

• You will run into problems if the page is nearly full: if you shorten it the text will wander to the next page and the number of the last page will oscillate. – Ulrike Fischer Nov 5 at 8:45
• @UlrikeFischer Do you mean that it is not stable to use \iflastpage to change the geometry of the last page? If yes, is there any other way to do so? – Diaa Nov 5 at 9:05
• I would simply put the text "End of the Exam" at the end of the document. – Ulrike Fischer Nov 5 at 9:07
• @UlrikeFischer Unfortunately, this document resulted in this ugly output where End of the Exam is not placed just above the footer horizontal rule. – Diaa Nov 5 at 9:17