I am using \pagenumbering{gobble} to hide page numbers in some pages. I am also using fancyhdr and lastpage packages to show page numbers for other pages like -
Page \thepage of \pageref{LastPage}
However for gobbled pages it shows something like -
Page of 4 %only last page number is shown
I want to hide the whole thing when \thepage is gobbled.
What I have tried so far is -
\rfoot{\ifnum \thepage>0 Page~\thepage~of~\pageref{LastPage}\else \fi}
This compiles and works as intended, but there is a error message when \newpage is incountered.
Missing number, treated as zero. \newpage
I have also tried to use \@ifundefined as was suggested in this answer but couldn't get it to work
Can anyone suggest any ideas?
Here's a compilable sample document source.
\documentclass[11pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[left=1.00in, right=1.00in, top=1.00in, bottom=1.00in]{geometry}
\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0.4pt}% default is 0pt
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{\ifnum \thepage>0 Page~\thepage~of~\pageref{LastPage}\else \fi}
\begin{document}
\pagenumbering{gobble}
First Page
\newpage
Second Page
\newpage
\pagenumbering{arabic}
Third Page
\newpage
Forth Page
\end{document}
I am using portable miketex for windows.

\fancyhf{}to clear all the fields instead of\lhead{}etc. – Aug 30 '16 at 12:17