# LastPage not working with HyperRef

I'm trying to use hyperref to enable clickable content in my toc.

My main file:

\documentclass[12pt]{report}
\usepackage{ragged2e}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{color}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{hyperref}
\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\renewcommand{\thesection}{\arabic{section}}

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\includegraphics[height=0.8cm,width=0.75\linewidth]{image/logo}}
\fancyfoot[R]{Page \thepage \ of \pageref{LastPage}}

\title{Report}

\begin{document}

\maketitle
\pagestyle{fancy}

\include{PartA}

\end{document}


But i'm getting an error:

File        | Type   | Line   | Message

Report.tex  | Error | line 60 | !Argument of Hy@setref@link has an extra }. <inserted text>\par \include{PartA}

Report.tex  | Error | line 60 | !Paragraph ended before \Hy@setref@link was complete. <to be read again>\par \include{PartA}

Report.tex  | Error | line 60 | !Extra }, or forgotten \endgroup.

etc...


If i comment the

\pageref{LastPage}


The report compiles and works ok.

\fancyfoot[R]{Page \thepage \ of } %\pageref{LastPage}}


So i don't know why lastpage doesn't work with hyperref. Can anyone help me?

Thanks

• Your posted code works for me. So perhaps something else in your PartA is triggering the problem. – Andrew Swann Apr 6 '17 at 10:31
• Could you please use a package for blind text, such as lipsum or kantlipsum to produce several pages with text? (instead of \include{...}-ing something we don't have.) If I do so, your example works for me. – AlexG Apr 6 '17 at 10:32

I had also problems using hyperref and lastpage. The error
... LaTeX Warning: Reference LastPage' on page 2 undefined on input line 12. 
My rhead looked like this  \rhead{\footnotesize \thepage/\pageref{LastPage}}  I stumbled over this question Hyperref marks lastpage as a reference and the used the same solution, i.e. replacing \pageref with \pageref*.
\rhead{\footnotesize \thepage/\pageref*{LastPage}} `