# How to know if page is empty

Looking for macro to know if the current page is empty , and opening new page if were not as well. Is there any idea to do that? example in this MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}

\newcommand{\border}{\begin{tikzpicture}[remember picture, overlay]
\coordinate (top) at ($(current page.north)+(0,-1.5)$);
\coordinate (bottom) at ($(current page.south)+(0,1.5)$);
\coordinate (left) at ($(current page.west)+(1.5,0)$);
\coordinate (right) at ($(current page.east)+(-1.5,0)$);
\draw[red] (bottom-|left) rectangle (top-|right);
\end{tikzpicture}}

\begin{document}

\lipsum

\border

\end{document}


I want to put the frame in a blank page after the text

-
Define "empty". No content but has a header/footer? How about creating a minimal working example (MWE) that shows what you mean by "empty" and "not empty" in addition to the result from this condition. – Werner Jul 25 '14 at 16:59
i mean 'empty page' totally blank – salim bou Jul 25 '14 at 17:03
You can insert \newpage or \clearpage to move to a blank page. – Werner Jul 25 '14 at 17:19

My guess: \newpage is what you are looking for. It starts a new page, if there is something. Otherwise \newpage does not cause a page break.
@Heiko What's the difference between \newpage and \clearpage? When should one be used and not the other? – Manuel Jul 25 '14 at 18:18
@Manuel, \clearpage: macro:->\ifvmode \ifnum \@dbltopnum =\m@ne \ifdim \pagetotal <\topskip \hbox {}\fi \fi \fi \newpage \write \m@ne {}\vbox {}\penalty -\@Mi As you can see, \clearpage makes use of \newpage. – Sigur Jul 25 '14 at 18:35
@Manual \clearpage additionally flushes pending float objects. – Heiko Oberdiek Jul 25 '14 at 18:38