I want to refer to the last page of an included PDF document.

```
\documentclass{article} 
\usepackage{pdfpages}

\begin{document} 
\label{pg:mydoc}
\includepdf[pages=-]{mydoc.pdf}

The included pdf is on pages 
\pageref{pg:mydoc} -- x.

\end{document}

```

x should be the last page of the PDF. I have a solution, but I wonder if there is a more simple one.

```
\documentclass{article} 
\usepackage{pdfpages,refcount}

\newcommand*{\pdfnumberofpages}[1]{%
  \directlua{%
    local doc = epdf.open("\luatexluaescapestring{#1}")
    local pages
    if (doc) then
      pages = doc:getCatalog():getNumPages()
    else
      pages = 0
    end
    tex.write(pages)
  }%
}

\newcommand\pagerefoffset[2][0]{%
\edef\tmp{\getpagerefnumber{#2}}%
\the\numexpr#1+\tmp\relax} 

\begin{document} 

\label{pg:mydoc}
\includepdf[pages=-]{mydoc.pdf}

The included pdf is on pages 
\pageref{pg:mydoc} -- \pagerefoffset[\pdfnumberofpages{mydoc.pdf}-1]{pg:mydoc}.

\end{document}

```