Referring to Second Last Page in pageref in lastpage package

I can use \pageref{LastPage} to give the reference of last page with lastpage package. The last page of document is the back cover so I don't want to count it. I wonder how to specify the second last page with lastpage package. Thanks in advance for your help.

-

Use refcount to manipulate (page) reference:

\documentclass{article}
\usepackage{lastpage,refcount,atbegshi}
\usepackage{hyperref}
\usepackage{lipsum}
\AtBeginShipout{%
\ifnum\value{page}=\number\numexpr\getpagerefnumber{LastPage}-2\relax
\phantomsection\label{preLastPage}
\fi}
\begin{document}

Last page: \pageref{LastPage} \par
Second to last page: \pageref{preLastPage}

\lipsum[1-50]

\end{document}


The reason for comparing \value{page} with <LastPage>-2 is because of the fact that page numbers are stepped after printing the value - different from other counters in a document. So, \AtBeginShipout, the page counter has already been stepped and we need to insert a \label at the end of page <LastPage>-2 in order for it to be set at the start of page <LastPage>-1.

-
(+1) Thanks @Werner for your nice answer. It works like a charm except the hyperlink is broken. Any thoughts. – MYaseen208 Aug 7 '14 at 19:47
@MYaseen208 There can be no link if there is no anchor. – egreg Aug 7 '14 at 20:10
@MYaseen208: I've updated my answer. For future reference, please include a minimal example that shows you're hyperref. – Werner Aug 8 '14 at 2:16

The pageslts package puts a last page label for each numbering scheme, provided you use a pagenumbering{…} at the beginning of the document, and at every scheme change. So, for your cover page, you can use any scheme not used beforehand, setting \pagestyle{empty} immediately after:

\documentclass{article}
\usepackage{pageslts,refcount}
\usepackage{lipsum}
\usepackage[ plainpages=false, pdfpagelabels=true]{hyperref}

\begin{document}

\pagenumbering{arabic}
Last page: \pageref{pagesLTS.arabic} \par
Very last page:  \lastpageref{LastPages}

\lipsum[1-50]
\clearpage
\pagenumbering{roman}
\pagestyle{empty}
section{New page numbering}
\lipsum[51-60]

\end{document}


Note that the options to hyperrefare set to prevent any problems if two pages have the same number (even in different numbering schemes), according to the documentation (§ 3.1), but aren't really necessary for the example given here. See the details of constraints in the doc.

-